Crab.run() (Idea)

From 8x9craft
Revision as of 03:09, 23 February 2017 by Maciek (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

It would enable users to build more complicated programs and reuse blocks of code (like procedures) that all run in their own scope.

// Program: forward.inc
for (let i = 0; i < 4; ++i) crab.forward();
crab.turnLeft();
crab.run('build_a_house');
crab.turnLeft();
crab.turnLeft();
crab.run('build_a_house');
crab.turnLeft();
for (let i = 0; i < 4; ++i) crab.back();

// Program: village
for (let i = 0; i < 4; ++i) {
    crab.run('forward.inc');
    crab.turnLeft();
}

See also