Skip to content

Instantly share code, notes, and snippets.

@rileydutton
Last active December 16, 2015 19:28
Show Gist options
  • Save rileydutton/5484853 to your computer and use it in GitHub Desktop.
Save rileydutton/5484853 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 > 18) {
//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
});
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 B...");
var patroltoken = findObjs({_type: "graphic", name: "Guard B"})[0]; //We know there is a token in the Campaign called "Guard A".
if(!patroltoken) {
log("NO GUARD B");
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 > 20) {
//Switch directions!
direction = direction * -1; //will "flip" the direction we're walking
stepstaken = 0; //reset steps back to 0.
}
var df = Math.floor(stepstaken / 7);
var thisdirection = direction;
var topleft = "top";
if(df == 0) {
topleft = "top";
}
else if(df == 1) {
topleft = "left";
}
else if(df == 2) {
topleft = "top";
thisdirection = direction * -1;
}
patroltoken.set(topleft, patroltoken.get(topleft) + thisdirection); //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