Skip to content

Instantly share code, notes, and snippets.

@raphaelbastide
Last active December 21, 2015 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raphaelbastide/6356889 to your computer and use it in GitHub Desktop.
Save raphaelbastide/6356889 to your computer and use it in GitHub Desktop.
modul comunication function
// emission
function com(msg){
var siblingModuls = modul.sonar();
if(siblingModuls.length === 0){
ui.log("Nothing sent, you seem alone…");
}else{
var modul1 = siblingModuls[0];
var modulimg = modul1.image();
modul1.send(msg);
ui.log("Your modul sent “"+msg+"”");
}
}
// reception
modul.on( 'message', function( fromModul, message ){
if (message === "dog"){
fromModul.send("V•ᴥ•V"); // automatic message
}else if(message === "go right"){
// the modul can be remote controlled by another modul
modul.move("right");
}else if(message === "go left"){
modul.move("left");
}else if(message === "go top"){
modul.move("top");
}else if(message === "go bottom"){
modul.move("bottom");
}
ui.log(fromModul.name+" says “"+message+"”");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment