abs
abs(a) returns the absolute value of a.
mathematical: |a|
The number a becomes positive, if it was negative. The number stays positive, if it was positive.
Example:
abs(-3) = 3
abs(7) = 7
Where can you use the abs function?
We want to write an example program, where an object jumps randomly inside a frame but is not allowed to jump outside. If it would jump outside it is again placed in the middle at x=0 and y=0.
So we can start with an forever loop. In this loop we can put in some blocks to randomly change x and y by some number. And it would be a good idea also to put in an wait 1 second block. After that we can take an if-clause with the condition so that if the object jumps outside of the frame. In my case the frame was on x = ±492, so if clause is if [abs( position x ) ≥ 492] is true then place at x=0 and y=0. The next blocks are same with position y.
Code: