Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Current »

What Are Variables

A variable can be seen as container to store a value. There are variable types for single values:

  • Integers contain positive and negative numbers like 3, 15457, -644, or 7432854.
  • Floats are numbers with digits such as 3.14, -8454.9644, or 7.73211
  • Strings contain text enclosed in quotes, e.g. "Warning: Domains have different resolution settings!", or "Object successfully loaded."
  • Booleans are True or False

Other variable types are able to store more than value:

  • Vectors contain three values. Typical examples are position, velocity, or rotation.
  • Lists can store huge amounts of data like a domain's particles, a project's objects, or all density values of a particle simulation.

Assigning Variables

Assigning a value to a variable is easy:

  • Integer: id = 100
  • Float: pi = 3.14
  • String: domain = "DY_Domain01"
  • Boolean: flag = True
  • Vector: velocity = Vector.new(3.5, -1.4, 0.7)
  • List: objects = ["Sphere", "Cube", "Tours", "Cylinder"]

 

A few tips:

  • Always use meaningful variable names to avoid confusion and keep your scripts readable.
  • When a name is used again its original value will be overwritten.
  • Only use the following characters for variable names: A-Z, a-z, 0-9, and the underscore
  • Lists can contain different variable types, even other lists or variables, e.g. mixedValues = ["Cube01", 3.14, 200, ["DY_Emitter01", "DY_Emitter02"]]

Working with Variables

With variables it is possible to perform all kinds of calculations, but the data type (integer, float, vector) has to be exactly the same. Otherwise you will get errors or false results:

  • vector3 = Vector.new(0,1,0) + Vector.new(1,0,1)
  • mass    = 677.533 / 2.0
  • newId   = 3 * 100

 

You cannot perform calculations with lists and Booleans, but strings can be concatenated and repeated:

  • newName = "Sphere"+"_Imported"
  • warning = "Don't touch this parameter! " * 3
  • No labels