Skip to content

Instantly share code, notes, and snippets.

@raphaelbastide
Created August 27, 2013 23:27
Show Gist options
  • Save raphaelbastide/6360347 to your computer and use it in GitHub Desktop.
Save raphaelbastide/6360347 to your computer and use it in GitHub Desktop.
thx bpierre
var activeGoto = false;
var posGoto = [0,0];
function goto() {
var c = modul.coordinates();
if (c[0] > posGoto[0]) {
modul.move("left");
} else if (c[0] < posGoto[0]) {
modul.move("right");
}
if (c[1] > posGoto[1]) {
modul.move("top");
} else if (c[1] < posGoto[1]) {
modul.move("bottom");
}
if (c[0] === posGoto[0] && c[1] === posGoto[1]) {
ui.log("End of the trip!"); // never shown?
activeGoto = false;
}
}
function initGoto(x, y) {
posGoto = [x, y];
activeGoto = true;
}
function stopGoto() {
ui.log("Trip stopped"); // never shown?
activeGoto = false;
}
world.on('interval', function(){
if (activeGoto) goto();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment