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.
Create
Section titled “Create”- Select the object. In the Inspector, under Variables, click + Variable and pick the type.
- 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 |
Use in code
Section titled “Use in code”function onUpdate(self) self.x = self.x + axis("esquerda", "direita") * self.velocidadeendclass Player : public brasa::Entity {public: BRASA_VARS(Player)
void onUpdate() override { x += axis("esquerda", "direita") * velocidade; }};- Lua: variables are fields of
self, already holding the instance value inonSpawn. - C++:
BRASA_VARS(Class), right afterpublic:, 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.
Value per instance
Section titled “Value per instance”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)onTouchStart<Player>([this](Player&) { goTo(destino); });- 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.
