Show HN: JSRobot – A platform game you play by coding in JavaScript
github.com
github.com
function init(robot){
robot.number = 0;
}
function loop(robot){
robot.jump();
if(robot.number++ % 2 == 0){
robot.move(2);
}
}
This is in the second level.Incrementing inside a check is awkward, as is just calling the variable 'number'. Perhaps something like
function init(robot){
robot.jump_next = true;
}
function loop(robot){
if (robot.jump_next) {
robot.jump()
robot.jump_next = false;
} else {
robot.move(2);
robot.jump_next = true;
}
}Though that is slightly different (since ++ will execute after the conditional is evaluated when following the lval but the change will make it run before)
Edit: on 2 seconds though... put that code AFTER the if statement and it would behave exactly as the example.
If that wasn't the case, then swapping things around to be something more like "move_next_turn" would be clearer I think.
The best part of the previous discussions is links to similar technologies; I look forward to seeing what else is mentioned today.
Blockly is a library for building visual programming editors | https://news.ycombinator.com/item?id=10763057 (Dec 2015, 40 comments)
Google's Blockly Games | https://news.ycombinator.com/item?id=8211031 (Aug 2014, 18 comments)
Google Blockly - a visual programming language | https://news.ycombinator.com/item?id=4050426 (Jun 2012, 123 comments)
--
http://learn.code.org/hoc/1 - highly polished Hour of Code
https://tickleapp.com/ - Blockly <-> Swift controlling physical hardware
Was the pun intentional here?
Using Firefox 56.
It was a lot of fun to build but ultimately I just wanted to play the game manually. Someone who tried it back when we released actually wrote a script to control the game turn-by-turn via alert boxes, hah.
[0] https://github.com/bovard/raid
[1] http://7drl.org/
Overall, great work though.
[1] https://en.wikipedia.org/wiki/Karel_(programming_language)
In-line incrementation and Mod operations on level 2 is a fast way to lose beginner interest.
I still think Python is the most straightforward to learn, even though the whitespace constantly catches beginners out too.
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
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. { 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. function loop(robot){
// your code here
robot.move(1)
robot.jump()
}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...