Okay. I watched the Pet Store Card video about 100000 times and after some modifications I have come up with the following code:
==================================
//store the factCard textures in an array
let facts = [symbol.controllers.factCard.elements.Fact1,
symbol.controllers.factCard.elements.Fact2,
symbol.controllers.factCard.elements.Fact3,
symbol.controllers.factCard.elements.Fact4];
//variable used in the random calculation directly below and in the changeFact function on line 93
let fact = 3;
//calculate a random number from 0-5 corresponding with a texture state from the facts array
let randomfact = Math.floor((Math.random() * fact));
//activate a random fact each time the card is scanned
parent.on(“ready”, function () {
facts[randomfact].activate();
});
//change the fact’s skin texture when the user presses fact card
symbol.nodes.factoid.on(“pointerdown”, (e) => {
changeFact();
});
//change the fact’s texture when it’s tapped on, called from the pointerdown event handler function above
function changeFact() {
fact += 1;
if (fact >= facts.length) {
fact = 0;
}
}
What is working in this script:
- A Random fact is being loaded each time the zapcode is scanned.
What is not working in this script:
The user ability to tap the card to change the fact.
I have set up a controller “factCard” and it has 4 states - Fact1 (default), Fact2, Fact3, Fact4
I am not sure why this isn’t working. I am sure it is my fault and I am missing something, but can’t figure out what.