Local Variable

From LuaSTG Wiki
Jump to navigation Jump to search

Create local variable node allows one or more local variables to be declared. This node does the job with editor node as a replacement of declaring variables with raw Lua code.


Example of Use[edit | edit source]

After a variable is created with this node, it can be put into other nodes as a parameter by entering its variable name in the corresponding parameter slot on the left side of the editor. Create local variable example.png

Create local variable parameter slot.png

In the above image, the Velocity attribute of the node is set to speed, and the Angle attribute of the node is set to shootAngle. When we run the script, a simple bullet will be shot downwards at -90° with its speed set to 3. In this case the type of the variable we create is number, but in general a variable can also be assigned values of other types.

The above create variable node will get translated to something similar to "local speed = 3 local shootAngle = -90" when the script is run.


Variable Types[edit | edit source]

Same as declaring variable with raw Lua code, a variable can be assigned one of the following types of values:

  1. number: 3, 10, 0.9, -2.7 / 5, Angle(self, player)
  2. boolean: true, false
  3. string: "abc", "Junko"
  4. list: {}, {1}, {3, "b", false}
  5. function: Angle, hypot, math.sqrt
  6. nil

Remember that bullet types are implemented with Lua classes, which are actually lists; bullet colors are implemented with constant numbers; bullets/enemies/bosses etc. themselves are lists as well. This means that we can create a local variable to hold values like arrow_big, COLOR_BLUE and so on.