4 ms·
It's a nice idea and really well executed but the second test just demonstrates to me how JS is not an ideal language for a beginner to learn as you're thrown s
by bjpirt 9y ago
It's a nice idea and really well executed but the second test just demonstrates to me how JS is not an ideal language for a beginner to learn as you're thrown straight into async execution and having to work around the fact that functions execute immediately with arcane workarounds.
I still think Python is the most straightforward to learn, even though the whitespace constantly catches beginners out too.
- always_good 9y agoI 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
- kaoD 9y agoI 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.
- reacweb 9y agoOr 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.
- positivecomment 9y agoExactly, 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.
- always_good 9y agoAnother 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.
- IanCal 9y agoThat'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() }
- kaoD 9y agoIt 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/478848147a080d8bf6ded8689d523337ea5e5ff7/scripts/Robot.js#L41 https://github.com/reaalkhalil/JSRobot/blob/478848147a080d8b...
- IanCal 9y agoAh I stand corrected, thanks. So I guess it's performing the last valid action.