Keep data between rooms
Global object
Section titled “Global object”It spawns once, in the first room, and exists in all of them. It is the place for score, lives and game state.
- Create an object (
Controle) with the variablesmoedasandvidas. - In Project › Project settings… › Global objects, click + Global object and pick it.
self:onTouchStart("Player", function() local controle = instance("Controle") controle.moedas = controle.moedas + 1 self:destroy()end)onTouchStart<Player>([this](Player&) { instance<Controle>()->moedas += 1; destroy();});Persistent object
Section titled “Persistent object”Check Persistent in the object Inspector. The instance moves to the next room with its variables, timers and position.
