Writing Procedures And Functions

Writing Procedures And Functions

You are here:
← All Topics

Procedure is a sequence of commands which together performs some given logic for example let’s say we want to “shake” the world so we write a simple procedure which turns the camera to the left and to the right very fast 10 times causing an illusion of a “shaking” world:

skybox.show "lagoon"

do 10 times
 camera.turn left 5 in 0.1 seconds
 camera.turn right 5 in 0.1 seconds
end do

Notice the “do” and “end do” commands. They state the beginning and end of our procedure. The latter “10 times” states that we would like to perform this procedure 10 times in a loop.
We can give the procedure a logical name and hence making it a “function“.
A function will not work until you call (run) it:

skybox.show "lagoon"

function shake_world = do 10 times
 camera.turn left 5 in 0.1 seconds
 camera.turn right 5 in 0.1 seconds
end do

run shake_world 

Notice the “run shake_world” command which calls the function. Without it the function would still exists but nothing will happen.



Previous Writing Non-Blocking Code