Good night folks.
I’m new to programming, less than 2 months, so I don’t quite understand how to make this work. Here’s exactly what I want to do:
I have this game I’m trying to make which needs to do a raffle between existing units that fit the condition “is alive” and have “is able to use the prize”. To do that, I was told I needed to include an array with the unit Id for the units that can receive it, then filter them by “is alive” to choose from by a random generator. Thing is, I have no idea how to make this work. I’ve tried this code, but it does not work. Anyone has any idea why or how I should do it instead?
var rafflearray = []; // the array containing the units
if (root.getExternalData().isUnitRegistered() = true) {var character = root.getCurrentSession().getPlayerList().getData()}; // establish the character as a variable
if (var character.getAliveStatus = true ) {rafflearray.push(character)}; // checks his alive status and send him to the array
var chosen = rafflearray [Math.random()*chosenarray.lenght]; // to choose amongst them
chosen.addItem()
Thanks in advance for the attention!