Set variable in <target action> to use for if...then statement

Hello there,


So, I'm having trouble with a particular skill.  I want it to randomly choose from among 8 possible outcomes.  I'm using a random number between 1 and 8 assigned to a value which should then be read by the if...then statement to decide which outcome to choose, but either the variable isn't being set to said random int or the if...then isn't reading the variable.  It always performs the default action (nothing) for if the variable isn't set to a number between 1 and 8.


I'm using yanfly's Battle Core notetags to do this, so everything happens in a <target action> as part of a skill notetag.


I am not JS fluent (at all), so I'm guessing that I'm probably missing something elementary.  Any ideas on how to fix this?

Code:
<target action>
eval: $gameVariables.setValue[10] = Math.randomInt(8)+1;
perform action
if ($gameVariables.value[10] == 1)
   animation 3: target
   eval this.elementID = 4
   action effect
   add state 12: target
else if ($gameVariables.value[10] == 2)
   animation 4: target
   eval this.elementID = 5
   action effect
   add state 13: target
else if ($gameVariables.value[10] == 3)
   animation 5: target
   eval this.elementID = 6
   action effect
   add state 14: target
else if ($gameVariables.value[10] == 4)
   animation 2: target
   action effect
   add state 5: target
else if ($gameVariables.value[10] == 5)
   animation 2: target
   action effect
   add state 6: target
else if ($gameVariables.value[10] == 6)
   animation 2: target
   action effect
   add state 15: target
else if ($gameVariables.value[10] == 7)
   animation 2: target
   action effect
   add state 16: target
else if ($gameVariables.value[10] == 8)
   animation 2: target
   action effect
   add state 17: target
else
   break action
</target action>
You use (number) for $gameVariables.value and $gameVariables.setValue, not [number]


I really have no idea if any of what you've got up there works with that plugin.  You seem to have a mix of script and plugin stuff and I don't know if it works that way.  But changing [] to () might get you further than you are now.
Hmm, thank you for the especially quick reply.  Changing [] to () throws an 'improper leftside argument' error.  But then removing the equation fixes that.


I.e.


$gameVariables.setValue(10, math.randomInt(8)+1)


But that kept spitting out the default output- the 'else' case.


So, this is where I'm at, now, and instead of giving the 'else' case, I'm only ever getting the var=1 case.


<target action>
eval: $gameVariables.setValue(10, Math.randomInt(8)+1)
perform action
if $gameVariables.value(10, 1)
animation 3: target
eval: this.elementID = 4
action effect
add state 12: target
else if $gameVariables.value(10, 2)
animation 4: target
eval: this.elementID = 5
action effect
add state 13: target
// clipped for ease of reading
else
break action
</target action>




I've spent an embarrassingly long amount of time on this and am going to sleep.
if ($gameVariables.value(10) === 1)


As I said, I don't know if you've got the right syntax or structure or anything.  I'm not familiar with the plugin (and you haven't provided a link).  You seem to be trying to mix plugin stuff with actual script calls and I don't know if that's going to work.  I suggest you go back to the plugin notes and see if those things are even possible in the context of the plugin.  I suspect they aren't.
Thank you very much, Shaz!  That line of code made the if...else statements work properly!  Here's the working form:


(again, this is a Skill notetag for yanfly's Battle Engine Core plugin)

Code:
<target action>
eval: $gameVariables.setValue(10, Math.randomInt(8)+1)
perform action
if ($gameVariables.value(10) === 1) 
   animation 3: target
   action effect
   add state 12: target
else if ($gameVariables.value(10) === 2) 
   animation 4: target
   action effect
   add state 13: target
else if ($gameVariables.value(10) === 3) 
   animation 5: target
   action effect
   add state 14: target
else if ($gameVariables.value(10) === 4) 
   animation 2: target
   action effect
   add state 5: target
else if ($gameVariables.value(10) === 5) 
   animation 2: target
   action effect
   add state 6: target
else if ($gameVariables.value(10) === 6) 
   animation 2: target
   action effect
   add state 15: target
else if ($gameVariables.value(10) === 7) 
   animation 2: target
   action effect
   add state 16: target
else if ($gameVariables.value(10) === 8) 
   animation 2: target
   action effect
   add state 17: target
else
   break action
</target action>

Original thread: https://forums.rpgmakerweb.com/threads/set-variable-in-target-action-to-use-for-if-then-statement.70072/