Skip to content

Instantly share code, notes, and snippets.

@rileydutton
Created April 30, 2013 14:19
Show Gist options
  • Save rileydutton/5489038 to your computer and use it in GitHub Desktop.
Save rileydutton/5489038 to your computer and use it in GitHub Desktop.
// Guards on patrol...
on("ready", function() {
//Wait until the ready event fires so we know the campaign is completely loaded.
//Get a reference to our patrolling token.
log("Going Guard A...");
var patroltoken = findObjs({_type: "graphic", name: "Guard A"})[0]; //We know there is a token in the Campaign called "Guard A".
if(!patroltoken) {
log("NO GUARD A");
return;
}
var direction = -70; //Walk left 70 pixels.
var stepstaken = 0; //How many steps have we walked in the current direction?
setInterval(function() {
if(patroltoken.get("status_greenmarker") === false) return;
if(stepstaken > 9) {
//Switch directions!
direction = direction * -1; //will "flip" the direction we're walking
stepstaken = 0; //reset steps back to 0.
}
patroltoken.set("left", patroltoken.get("left") + direction); //walk!
stepstaken++;
}, 3000); //take an action every 5 seconds
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment