
Show HN: JSRobot – A platform game you play by coding in JavaScript - reaal
https://github.com/reaalkhalil/JSRobot
======
IanCal
Interesting, you might want to look at the suggested code though, maybe play
through with some beginners?

    
    
        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;
            }
        }

~~~
styfle
The first snippet calls robot.jump() every loop. The second doesn’t not.

~~~
IanCal
True, although as someone else points out (contrary to what I thought) only
the last runnable action is done.

If that wasn't the case, then swapping things around to be something more like
"move_next_turn" would be clearer I think.

------
j_s
If I remember correctly, Google's Blockly Games used to allow JavaScript on
more than just the last "level". It definitely starts at a much earlier point
in the learning process.

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](https://news.ycombinator.com/item?id=10763057)
(Dec 2015, 40 comments)

Google's Blockly Games |
[https://news.ycombinator.com/item?id=8211031](https://news.ycombinator.com/item?id=8211031)
(Aug 2014, 18 comments)

Google Blockly - a visual programming language |
[https://news.ycombinator.com/item?id=4050426](https://news.ycombinator.com/item?id=4050426)
(Jun 2012, 123 comments)

\--

[http://learn.code.org/hoc/1](http://learn.code.org/hoc/1) \- highly polished
Hour of Code

[https://tickleapp.com/](https://tickleapp.com/) \- Blockly <-> Swift
controlling physical hardware

------
ahmeni
A neat concept but frustrating when restarting the page loses any code in the
script window.

~~~
reaal
Sorry! That's next up on the todo list

------
Confiks
It's an interesting game, but I was immediately put off by level two, which
sinks you into the limitations of the robot API by making you introduce a
counter that needs checking. That would be totally counter-intuitive for
beginners.

~~~
mathgeek
> ...introduce a counter that needs checking. That would be totally counter-
> intuitive...

Was the pun intentional here?

~~~
Confiks
No. In fact, initially I put "unintuitive" there, but the spelling-checker
marked it as an unknown word while it is perfectly valid English.

------
benlower
Stops working for me after level 1. Repro: 1\.
[https://lab.reaal.me/jsrobot](https://lab.reaal.me/jsrobot) and click "start"
2\. Complete the level and click "next level" 3\. This takes me to
[https://lab.reaal.me/jsrobot/#level=2](https://lab.reaal.me/jsrobot/#level=2)
but the screen is blank 4\. Dev tools shows this: "ReferenceError: URLcode is
not defined[Learn More] ui.js:32:5"

Using Firefox 56.

~~~
TruthSHIFT
I'm get the same error in Chrome 61.

~~~
reaal
Sorry about that, fixed

------
cdubzzz
I contributed to a similar project[0] for the 2016 7DRL[1].

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](https://github.com/bovard/raid)

[1] [http://7drl.org/](http://7drl.org/)

------
throwaway2016a
Reminds me of a course I had to take freshman year in college called Karel the
Robot[1]. It had a Basic like programming language. It mostly existed to try
to quickly bring up to speed the students that has no experience coding prior
to college. This is interesting because Javascript is a much more complete
language and probably also a it harder to learn if you are just getting
started.

Overall, great work though.

[1]
[https://en.wikipedia.org/wiki/Karel_(programming_language)](https://en.wikipedia.org/wiki/Karel_\(programming_language\))

------
adbachman
:/ Fun idea, but I wrote a chunk of code for the third level, bumped the
electro thing, died, clicked the restart button and it wiped my script. I
should know better than to trust browser based text editors, but it made
iteration and exploration difficult.

~~~
reaal
Sorry about that, I lazily made the page refresh to restart a level, will fix!

------
reaal
UPDATE: I've fixed the issue where restarting the level clears the script

------
SeanDav
On the right track, but waaaay to steep a learning curve for an absolute
beginner, assuming that is the target audience.

In-line incrementation and Mod operations on level 2 is a fast way to lose
beginner interest.

------
xori
Another example in Action/RPG format

[https://codecombat.com](https://codecombat.com)

------
allenleein
This game is simply amazing. Better interactive tutorial for beginner than
Codecademy.

------
jlebrech
document.write("<h1>you win</h1>")

------
raresp
Great resource for learning Javascript. Good work!

------
bjpirt
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
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

~~~
kaoD
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.

~~~
reacweb
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.

~~~
positivecomment
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.

