Last active
December 21, 2015 19:49
-
-
Save raphaelbastide/6356889 to your computer and use it in GitHub Desktop.
modul comunication function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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