Calculating the remainder of a division

Mar 26, 2018

Hi All,

Is there a way to calculate and assign the remainder of a division calculation to a variable?

Say if I divide 10 by 4, I should be able to assign the remainder value 2 to a new variable.


Senthil R

5 Replies
Matthew Bibby

Not sure if this can be done directly in Storyline (it is probably possible, but I've never tried).

It is pretty easy to do if using some JavaScript. 

Here is a demo.

Here is the source file (SL360).

To do this yourself, setup three number variables in Storyline (FirstNumber, SecondNumber, Remainder) and then pop this into an Execute JavaScript trigger:

var player = GetPlayer();
var num1 = player.GetVar("FirstNumber");
var num2 = player.GetVar("SecondNumber");
var rem = num1 % num2

Hope that helps. 

Walt Hamilton

For anybody that is interested in this sort of challenge, this sample does it with SL triggers, using repeated subtraction.

The problem is that if the first number is too big, it doesn't complete the process. Set number 1 to 1000 and number 2 to 5 or less, and the process ends before finishing. I thought it was because Slide 1 is recursive, and its iterations exceeded SL's ability to keep track. But Slide 2 isn't recursive and it processes more iterations, and still halts before completing. I conclude that the calling process and the action take different amounts of time, and eventually one simply outruns the other with the result that the cycle is broken on both slides.

I solved the problem by introducing a pause on slide 3 in the form of an animation, but the minimum length of an animation is 0.1 sec which is too slow.

 I tried using a layer timeline (slide 4) because they can be set to .01 sec, but showing the layer apparently takes more time and gives only about 120 iterations.

So unless you have fewer than about 220 iterations (for the slide 1 method) or 250 (for the slide 2 iteration), Javascript is your best bet.

The sample is included for anybody that wants play with it and find a method of doing this using only triggers.

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