It's the name of the object that the function is taking as parameter. In the context of the program it's not explicitly clear what that parameter is, but it can be deduced that it's the object for which said function is called for (eg. if something collided with that object.)
To you. I've never even heard of it. Wikipedia's article makes my head spin.
Still not clear to me. I mean, "it can be deduced that it's the object for which said function is called for," is really hard to decipher. I get that all these little conventions make programming much more powerful, but it leaves people like me in the dust.
All this is reminding me how much I dislike object-oriented programming. It's bogged down in syntactical complexities and I never know (for example) whether the functions I call are acting on what's to the left or to the right of them.
Now get off my lawn, you crazy kids.
Edit: Here's my attempt at level 11:
Seems simple. Compiles. Even looks very similar to Bisqwit's solution. Execute the code and you get nothing. But Bisqwit's solution is syntactically foreign to me. It's a move command, but the argument starts with canmove, which should be a boolean. Ah, but it's followed by a question mark. Must be some kind of syntactic equivalent to an if-then statement. After that, it's 'right':'down' and I don't have a clue what that means.
I reiterate my claim that this game is great for learning JavaScript if you already know the tricks behind object-oriented programming and similar languages. And hell, knowing JavaScript itself outright doesn't hurt either.
I also noticed that your solution to level 7 was cut down to a few lines by use of an array. I didn't know how to construct arrays in JavaScript, so my solution was much less elegant.
I intentionally made my solutions shorter for the forum post. I initially solved them involving longer code. For example: if(current==a){ setcurrent(b); } else if(current==b) { setcurrent(c); } and so on.
On level 9, I copied "player.setPhoneCallback()" directly from the API and it gave me an error message:
TypeError: player.setPhoneCallback is not a function
Your code instead uses map.getPlayer().setPhoneCallback. Honestly, how was I supposed to know to use that?
I actually got stuck in that same situation for a long time. But if you pay attention, you see "var player = player.setPhoneCallback" in earlier levels, and you also have the API documentation to your disposal (this was what got me forward).
You also use an anonymous function, which I wouldn't confidently leap upon in a programming language I've never used before.
This was also taught in level 7 by example.
Bobo the King wrote:
I think you'll be laughing at how stupid my level 13 solution is. It's a minimal effort solution, basically the first thing I tried. "I don't feel like using my brain, let's see if this works!"
var r = Math.random() *10;
if (r < 1) me.move('up');
else if (r<3) me.move('down');
else if (r<5) me.move('left');
else me.move('right');
//Hit "Execute" till a level gets generated that looks like it could solve it
//Then run from left to right, eating popcorn with the other hand
I think you'll be laughing at how stupid my level 13 solution is. It's a minimal effort solution, basically the first thing I tried. "I don't feel like using my brain, let's see if this works!"
var r = Math.random() *10;
if (r < 1) me.move('up');
else if (r<3) me.move('down');
else if (r<5) me.move('left');
else me.move('right');
May I suggest an optimization!
var dirs=['up','down','left','right'], priorities=[0,1,1,2,2,3,3,3,3,3];
me.move(dirs[priorities[map.getRandomInt(0,9)]])
Yeah... That was actually the idea that what I went for first, too. :-)
This elaborate code for level 17 (pointers) calculates and highlights the actual solution to the puzzle. Surprisingly most of the puzzles it generates are actually unsolvable. You have to click Execute a few times to get a solvable one.
Nobody said you have to accept the puzzle as given to you.
In the first iteration of the loop, set up a connection from start to exit, then break out of the loop. Finding the top left and bottom right teleporters is easy, for example with an array sort. Then connect them, break and play.
Probably not intended, doesn't even need the canvas functions.
Just so you know, Bobo the King, Javascript only has to be syntatically correct to compile. Unlike a language like C# or Java, and like languages like Python, it can attempt to call non-existent methods, manipulate non-existent fields or variables, etc. and the code will fail (sometimes silently!) at runtime.
No, I don't like it either :D
Also, 'me' is whatever it was defined as in the current scope. ctrl+f for 'me' and look for the earliest use of it in the displayed code - it will probably be like me = map.getPlayer() so you know it's nonexistent, or it will be the parameter passed into a method, so it's probably a method that deals with the currently being acted upon object. or hasn't been defined yet, in which case you need to map.getPlayer() yourself. (Or maybe it's defined as 'player' or whatever. You have to take a look and see what's available.)
Even dumber:
(a=map['\x5fdisplay'].game)?a['\x5fstart'](22):
Apparently they patched the game: "you are not allowed to use '\x'!"
Ah well...
u=String['from'+'CharCode'](95);
(a=map[u+'display'].game)&&a[u+'start'](22);
Just so you know, Bobo the King, Javascript only has to be syntatically correct to compile. Unlike a language like C# or Java, and like languages like Python, it can attempt to call non-existent methods, manipulate non-existent fields or variables, etc. and the code will fail (sometimes silently!) at runtime.
Curiously in Objective-C, even though it's a fully-compiled language (ie. it's compiled right into the machine code of the target architecture, and there is no interpreter of any kind running some bytecode or such), you can call inexistent member functions and it won't fail to compile, and instead the existence of the function will be checked at runtime. (You might get a warning, but that won't stop the code from compiling.)
This isn't always an error. A good example is a so-called proxy object. This is an object that "pretends" to be another object by behaving exactly like that other object (it does so by forwarding all method calls ("messages") to the other object, and by answering to all introspective requests like that other object, and thus it looks to the outside exactly like it were of the type of that object even though it isn't.)
(One could ask: "What's the difference between a proxy object and, for instance, that object simply being inherited from that other object?" One big difference is that you can make the one and same proxy object, that's pretending to be an object of type A, to change and pretend to be of a completely unrelated type B. When you make the change, it stops looking like an object of the former type and start looking exactly like an object of the latter type.)
It also allows doing other useful stuff, such as being able to call the member functions with identical signatures of completely unrelated objects.
(Of course if you try to call a method that's not actually implemented by the object, the runtime will throw an exception. You can catch that exception if you want.)