Coding with variables
Using variables in your code is a great way to enhance your animations with ease.
a variable has a name and can be either a number or a string and its value can be changed while the program is running. You can refer to a variable from many places in your code.
let’s see an example for declaring a variable in SceneMax script:
Here, we declared a variable named distance which is a number equals to 0.4
Now we can use it in our program for example, let’s take a look at the following code:
Sinbad is a model
s is a Sinbad
do 21 times
s.move(y+distance) in 0.05 seconds
This simple program is simulating jumping and landing with gravity force. What we have done here is moving our Sinbad model 21 times using a loop (do – end do block), each time reducing our distance variable (which was initiated to 0.4) in 0.04
Since distance was initiated to 0.4 it will take exactly 10 loop iterations to bring it to zero and 10 more iterations to bring it to -0.4 hence simulating jumping (up and down) and gravity force because of the distance change in every loop iteration.