Discord
Login
Community
DARK THEME

how do you reset a game

how do you reset a game

I think calling init() should be enough.

It depends on how is structured your game. If in the init you have assigned a value to all the variable you want to change to restart, than it's ok, otherwise you have to use another approach. If you have something like this:

init = function()
  x = 0
  y = 0
end

update = function()
  if touch.press then
    x+=1
    y+=1
  end
  
  if reset_button_variable then
    init() // restart
  end
end

draw = function()
  screen.clear()
  screen.drawSprite("sprite", x, y, 50, 50)
end

Then you can simply call the init, as it will set the coordinates to the initial state (in the case you want that variable set to that state after the reset)

Otherwise you can create another function where you declare the initial state of all the variables after the reset:

reset_function = function()
  x = 0
  y = 0
  other_variable = 5
end

...

update = function()
  if reset_button_variable then
    reset_function()
  end
end

...

oke

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community