6

I'm stuck on Level 15 of Untrusted.

I've gotten this far with no actual knowledge of Javascript beyond knowing C and assuming things are the same. I see no possible solution to this puzzle without some trick of the language I don't know about- no matter what I put in there, player.killedBy() is going to be called, and the Professor is going to die.

Any hints?

6

You can put anything in there that doesn't exist. eg

player.killedBy(nothing);

When you go in the water it will then throw an error message because nothing doesn't exist.

7

Actually you can pass the level without throwing any exception, just hacking the code:

[line 32] player.killedBy('
');},'onCollision':function(player){map.getWidth(
);

Just replacing the "onCollision" action again with a function that doesn't do anything.
enter image description here

Then you can walk on water!!

  • I hate that I love your solution. Congratulations for the ingenuity. – Cristopher Mar 10 '19 at 7:20
3

You can use concatenation and short circuit the collision detection routine i.e.

map.defineObject('water', {
    'symbol': '░',
    'color': '#44f',
    'onCollision': function (player) {
        player.killedBy(''+map.placePlayer(1,1));
    }
});
2

Of course, the hint is in the name.

You've got to throw an exception.

  • But how? This answer is kinda useless without some instructions, don't you think? – Canadian Luke Apr 15 '14 at 5:22
  • I was intending it as more of a hint. – Schilcote Apr 15 '14 at 12:30
2

I like this way:

player.killedBy(function() { throw 'I am Jesus';} ());
1

You can't acrossing water, but you can pick it up.

map.defineObject('water', {
        'symbol': '░',
        'color': '#44f',
        'onCollision': function (player) {
            player.killedBy();},'type':'item','beha':function(me){me.move('up');
        }
    });
0

also u can use infinite recursion..

player.killedBy((function(){x=function(){x();};x();})());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.