Game Troubleshooting - Triggers, JScript, Inconsistent

Sep 16, 2016

Hi Forum,

I have four objects, each with a single animation path.  I would like to select one at random, move it along it's path, repeat forever.

I have created the following JScript code to change the Storyline Variable "rand1" to 1, 2, 3, or 4.  This code works - I've tested it by showing an alert and manually triggering the code 50+ times.  It always produces a number in that range.

var player = GetPlayer();
var rand1 = player.GetVar("rand1");
var randomnumber = Math.floor((Math.random()*(5-1)+1));
player.SetVar("rand1", randomnumber);

I have 4x triggers:

  • Execute the JScript, when Object animation completes (one for each object).

I have 4x triggers:

  • Move Object along motion path, when rand1 changes, if equal to number 1/2/3/4 for each object 1/2/3/4. 

I have a button that runs the JScript once, which begins the first animation, and everything continues from there.  Call it the "GO" button.

It works well.  I'm happy with the product.  HOWEVER - randomly, usually within 2-20 animations, it just stops.  I then have to hit the GO button again to re-run the JScript and start everything again.

I've checked through all my triggers, there are no errors (they all call the right script).  I've checked through all the code and tested/debugged it thoroughly.  I've even put in 100ms delay into the JScript code just in case there is an overlap.  Nothing works.  I even added an additional trigger to set "rand1" to "1" when "rand1" changes - if it is not equal to 1, 2, 3, or 4 (just to be sure).

Are triggers based on variable changing sometimes unreliable?

Any clues?

2 Replies
Simon Wood

I figured it out!

If the variable is randomly set (using the JScript) to the same number that it already contains, then the Storyline Trigger "when variable changes" isn't actioned!

Interesting - because from a programming perspective, it IS still changed (but to the same number).  But from a logic perspective, the value within has not changed.

Anyway - fixed!

This discussion is closed. You can start a new discussion or contact Articulate Support.