1. Home
  2. Docs
  3. General Programming
  4. Using variables

Using 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:

1
 var distance=0.4

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:

1
2
3
4
5
6
7
8
Sinbad is a model
s is a Sinbad

var distance=0.4
do 21 times
s.move(y+distance) in 0.05 seconds
distance=distance-0.04
end do

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.

 

 

Was this article helpful to you? Yes No

How can we help?