Forum Discussion
Trivia Game - Using Variables and JavaScript to remove answered questions from the deck.
Hi Owen,
Thanks for your response! The outcome is loaded into a single variable. The code that I'm using (which I got from another of these posts but that I can't find now) is below. I then have triggers that change the state of each flower when the single variable (FM) changes. It works when the Javascript is repeated because FM changes each time the code runs. Hopefully, that will also happen in the loop. Here's the code (with a shorter list of single variables than I am using just to save space):
var player=GetPlayer();
var nv1=player.GetVar("F1");
var nv2=player.GetVar("F2");
//to
var nv100=player.GetVar("F100");
var myArray = [nv1, nv2, ....., nv100];
var filtered1 = myArray.filter(function(x) {return x>0;});
var myNumber = filtered1[Math.floor(Math.random() * filtered1.length)];
player.SetVar("FM",myNumber);
var myVariable = "F" + myNumber;
player.SetVar(myVariable, "0");