How can I add a main menu to my game and variables that dont reset when closing the game?
I would like to add a main menu to my game with the buttons: play(execute game), options(easy mode, normal mode, hard mode and impossible mode(only availiable when highscore is higher than 100 in normal mode), credits(credits) and leaderboard(btw idk how to do the game online).
I would also like that the high-score didnt reset when closing the game.
Thanks
Also idk how to write in the game. I mean, the fist time you join the game you put your username and if its already been chosen then you have to put another username
No ones responding, so i will put in the credits the people who replies with a working code
Try looking at storage
in the API docs for values that are remembered across game instances. To create an online game, check the networking docs.
Thanks, but I was asking for a code, i am new to microstudio. I dont really understand how to do an online ranking(btw i need a main menu for that)
I am in the right path?
Mi code is the next:
serverInit = function()
worldrecord = 0
highscore2 = 0
highscore3 = 0
end
serverUpdate = function()
if highscore > highscore3 then
if highscore > highscore2 then
if highscore > wolrdrecord then
worldrecord = highscore
else
highscore2 = highscore
end
else
highscore3 = highscore
end
end
end
init = function()
a = 1
b = 1000
c = 1000000
end
update = function()
a += 1
b += 1
c += 1
end
load = function()
storage.get( "a", a )
storage.get( "b", b )
storage.get( "c", c )
end
save = function()
storage.set( "a", a )
storage.set( "b", b )
storage.set( "c", c )
end
For a list of high scores sorted high to low, you can use something like this:
high_scores = []
MAX_SCORES = 3
add_score = function(score)
high_scores.push(score)
high_scores = high_scores.sort().reverse().slice(0, MAX_SCORES)
end
init = function()
add_score(1)
add_score(4)
add_score(2)
add_score(6)
print(high_scores)
end
The code above will print [6, 4, 2] because there is a limit of 3 high scores.