Crab.waitFor*() (Idea)

From 8x9craft
Jump to: navigation, search

Enable synchronous waiting for events. This would allow to write programs without minding the state:

Examples

while (true) {
    crab.waitForChat('open');
    crab.setRedstoneOutput('back');
    crab.sleep(10);
    crab.clearRedstoneOutput('back');
    // and the door open
}
crab.say('Waiting for the signal');
crab.waitForChat('go!');
// start race
crab.say('Where should I go?');
var direction = crab.waitForChat();
if (direction == 'left') crab.stepLeft();
else if (direction == 'right') crab.stepRight();
else crab.say("I didn't understand that");

See also