Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Modern programming languages differentiate between two fundamental types of variables: global and local.  The difference lies in the way the variables are stored within your script. Local variables, as the name indicates, only actlocally inside a function. . A function always starts with a def statement and can be considered as a closed code segment. With simulation events scripts, these functions are not directly visible, because you cannot see any predefined functions in the editor, as with scripted emitters or daemons. The editors for emitters, waves and daemons all show an initializing function, e.g.:

  • def setInternalForce( emitter )
  • def updateWave( vertices, initPositions ) 
  • def setExternalForce( emitter )
  • def setExternalForce( body )

Directly below this statement your code begins. Whenever you are writing a variable to such a section it will be treated as local. This means that it cannot be transferred to other functions. The variable is only stored and used within the actual function. You do not have to mark or tag a variable as local – Python automatically treats a variable as local, independent of it is type. So all the variables from the previous examples and code snippets are local variables. With global variables it is different. They can be used over the entire script, multiple functions and even different script types, such as daemons. 

...