Skip to content
Download

Object variables

A variable is a named value, created on the object and tuned in the editor. Each instance in the room can have its own value.

  1. Select the object. In the Inspector, under Variables, click + Variable and pick the type.
  2. Set the name and the default value. The ⋮ button changes the type, reorders and deletes.
Type Holds C++
number Decimal number float
integer Integer int
yes/no true / false bool
text Text std::string
color Color Color
room, objeto, sprite, som Name of a project resource, picked from a list std::string
function onUpdate(self)
self.x = self.x + axis("esquerda", "direita") * self.velocidade
end
  • Lua: variables are fields of self, already holding the instance value in onSpawn.
  • C++: BRASA_VARS(Class), right after public:, creates the fields. Do not declare a field with the same name. Without the line, the Inspector shows a notice with a button to insert it.

Select the instance in the room and, under Own values, check the variable and change the value. Unchecked, the instance uses the object default.

self:onTouchStart("Player", function() goTo(self.destino) end)
  • C++: changing a value does not recompile; creating, renaming, deleting or changing the type recompiles on the next Play.
  • On rename, the editor updates the instances in every room and offers to change the name in the object code.
  • Renaming a room, object, sprite or sound updates the variables that point to it.