News for hackers. Stuff that matters.
Re:Show HN: JSRobot – A platform game you play by coding in ... by always_good on Monday October 23, 2017 @03:15AM (#15531307)
I don't understand. Are you referring to Level 2?

What's going on there is just that the robot can only enqueue a single action for the tick. So calling multiple actions will just overwrite the slot.

It's an implementation detail of the game. Maybe it's tougher for beginners or not the best trade-off, but it doesn't have much to do with Javascript

Re:Show HN: JSRobot – A platform game you play by coding in ... by kaoD on Monday October 23, 2017 @04:30AM (#15531633)
I think it's just a case of leaky abstraction. I'd change the API to something like:

    robot.action = { action: 'jump' };
    
    robot.action = { action: 'move', amount: 4 };

    etc.
Or if you want to keep the action creators:

    robot.action = robot.jump();
    
    robot.action = robot.move(4);
Which makes it obvious that there can only be a single action per loop call.
Re:Show HN: JSRobot – A platform game you play by coding in ... by reacweb on Monday October 23, 2017 @04:40AM (#15531664)
Or the action could be the return value. IMHO, trying to guess the physical model by experimentation is painful. Why not propose a debug button to display the state of variables during the execution of script.
Re:Show HN: JSRobot – A platform game you play by coding in ... by positivecomment on Monday October 23, 2017 @06:23AM (#15532058)
Exactly, the function should not be responsible to see if robot.action has any existing value. It should just return an action depending on the state.
Re:Show HN: JSRobot – A platform game you play by coding in ... by always_good on Monday October 23, 2017 @07:44AM (#15532408)
Another idea is to return a map of actions.

    { jump: true, move: 4, shoot: true }
Making the user increment a nonce and use the remainder operator just to do multiple actions simultaneously is pretty heavy.
Re:Show HN: JSRobot – A platform game you play by coding in ... by IanCal on Monday October 23, 2017 @06:40AM (#15532118)
That's not right. You can put more than one action in the loop. This slowly completes the level:

    function loop(robot){
      // your code here
      robot.move(1)
      robot.jump()
    }
Re:Show HN: JSRobot – A platform game you play by coding in ... by kaoD on Monday October 23, 2017 @07:22AM (#15532304)
It shouldn't according to its own instructions.

I bet jump() has something like `if (robot.touchingFloor) { action = 'jump'; }` which makes your code work because it doesn't overwrite the robot action if it can't actually jump.

Switch the order of actions and you'll see the robot never jumps because its action gets overwritten (as stated in the instructions tab).

EDIT: Here it is:

https://github.com/reaalkhalil/JSRobot/blob/478848147a080d8b...

Re:Show HN: JSRobot – A platform game you play by coding in ... by IanCal on Monday October 23, 2017 @03:58PM (#15536441)
Ah I stand corrected, thanks. So I guess it's performing the last valid action.