Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
Bobo the King wrote:
What exactly is "me"? The player? If so, that seems redundant and confusing.
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.)
Player (80)
Joined: 8/5/2007
Posts: 865
henke37 wrote:
Variable scope isn't a strange thing.
To you. I've never even heard of it. Wikipedia's article makes my head spin.
Warp wrote:
Bobo the King wrote:
What exactly is "me"? The player? If so, that seems redundant and confusing.
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.)
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:
if(me.canmove('down')){me.move('down')};
if(me.canmove('right')){me.move('right')};
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.
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
Bobo the King wrote:
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:
Edit: Here's my attempt at level 11:
if(me.canmove('down')){me.move('down')};
if(me.canmove('right')){me.move('right')};
Identifiers are case-sensitive. canMove, not canmove. Again, not something you can't figure out by judging the existing example code in the game.
Player (80)
Joined: 8/5/2007
Posts: 865
Bisqwit wrote:
Bobo the King wrote:
Edit: Here's my attempt at level 11:
if(me.canmove('down')){me.move('down')};
if(me.canmove('right')){me.move('right')};
Identifiers are case-sensitive. canMove, not canmove. Again, not something you can't figure out by judging the existing example code in the game.
Oops.
Joined: 10/20/2006
Posts: 1248
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
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
Kuwaga 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');
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. :-)
Tub
Joined: 6/25/2005
Posts: 1377
Bisqwit wrote:
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.
m00
Editor
Joined: 3/10/2010
Posts: 899
Location: Sweden
Most certainly not intended. But definitely in the spirit of the game.
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
henke37 wrote:
Most certainly not intended. But definitely in the spirit of the game.
Good point.
Patashu
He/Him
Joined: 10/2/2005
Posts: 4045
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.)
My Chiptune music, made in Famitracker: http://soundcloud.com/patashu My twitch. I stream mostly shmups & rhythm games http://twitch.tv/patashu My youtube, again shmups and rhythm games and misc stuff: http://youtube.com/user/patashu
Player (146)
Joined: 7/16/2009
Posts: 686
scahfy wrote:
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);
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
Patashu wrote:
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.)
caitsith2
He/Him
Player (47)
Joined: 3/26/2004
Posts: 194
Level 9Built a bridge across the river https://gist.github.com/c28571817ecd0365c75b Level 10Closed off behaviour, and redefined the onCollision function https://gist.github.com/78bd91c685729f49c7d2 Level 15Closed off, and redifined onCollision https://gist.github.com/anonymous/170b72ed6c381bdc8afe Level 18Solutions based on creating additional 'block' objects no longer work. However, you can define your own impassable object, and use that instead. https://gist.github.com/916b85b19c50e4778729 Also a DROP tables style attack. This time, another timer slightly faster than gravity that will tend to pull you up, when you are over the bottomless pit. https://gist.github.com/df68c73b8142875cc584 Take a closer look at the gravity function, and see at how it checks if the player can move down, and note what I am using to bridge the gap. :) https://gist.github.com/f747b65270b64dc35a48 Level 20 They didn't say anything about creating a static object that will later create dynamic objects :) https://gist.github.com/anonymous/671815f9093a034a6706[/spoiler]
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
caitsith2 wrote:
<cool solutions>
I like the way you think.