I’m nearly done with ETA’s initiative functionality. However, one small problem remains. I don’t know how to make the token images match the initiative scores!
Here’s an example of what I mean. The following initiative scores are generated for each token and placed in order:
In this example, the order of token images should be (from top to bottom): green, gold, cyan, and magenta.
Here is the script in question. I’m open to ideas about how to make this work.
// generates initiative rolls for each tokenUI
goldTokenInitRoll = (pc.math.random(1, 21) + goldTokenInitMod).toFixed(0); console.log("Gold:", goldTokenInitRoll);
cyanTokenInitRoll = (pc.math.random(1, 21) + cyanTokenInitMod).toFixed(0); console.log("Cyan:", cyanTokenInitRoll);
magentaTokenInitRoll = (pc.math.random(1, 21) + magentaTokenInitMod).toFixed(0); console.log("Magenta:", magentaTokenInitRoll);
greenTokenInitRoll = (pc.math.random(1, 21) + greenTokenInitMod).toFixed(0); console.log("Green:", greenTokenInitRoll);
// place the rolls in an array
var rolls = [goldTokenInitRoll, cyanTokenInitRoll, magentaTokenInitRoll, greenTokenInitRoll];
// call the position function to order the rolls from greatest to least
console.log(rolls);
this.Position(rolls);
console.log(rolls);
// -------------------------------------------------------------------------------------------------------------------------
// make an array for the texture assets
var textures = [this.goldAsset, this.cyanAsset, this.magentaAsset, this.greenAsset];
//
// ideas for getting numbers and textures to match:
//
//
// ORDER THE POSITION ROLLS TOKEN IMAGES USING ATTRIBUTES
// this.app.root.findByName("Track_1st_Place_Img").element.texture = ;
// this.app.root.findByName("Track_2nd_Place_Img").element.texture = ;
// this.app.root.findByname("Track_3rd_Place_Img").element.texture = ;
// this.app.root.findByName("Track_4th_Place_Img").element.texture = ;
// print the initRolls to the initiative tracker
this.app.root.findByName("Track_1st_Place_Txt").element.text = rolls[0];
this.app.root.findByName("Track_2nd_Place_Txt").element.text = rolls[1];
this.app.root.findByName("Track_3rd_Place_Txt").element.text = rolls[2];
this.app.root.findByName("Track_4th_Place_Txt").element.text = rolls[3];
// disable this UI
// this.app.root.findByName("Init_Button").script.initTracker.deSelect();
this.app.root.findByName("Initiative_Gen_Group").enabled = false;
// enable the init tracker UI and bring it into frame
this.app.root.findByName("Init_Track_Group").enabled = true;
this.app.root.findByName("Init_Track_Group").setPosition(0, 0, 0);
};
// a function for ordering initRolls
InitRoller.prototype.Position = function(tokens) {
// orders the initiative rolls from first to fourth (descending order)
tokens = [tokens.sort(function(a, b){return b-a;})];
};