Discord
Login
Community
DARK THEME

Moneysave system

im making a game where you have money. i planed features with savegames so you dont lose your money and this is the code so far

    SaveGame = function()
      save = object Money = Money.Cash end
      storage.set("save",save)
      
      
end

  save = object Money = save.Money  end

here the public link to the project so you can help me

https://microstudio.io/i/Sammy4141/spielewettbewerb/

my problem is if i type in my console Money.Cash = 1 the save.money jumps up to 1 too because i coded it but if i restart the game the save.money is at zero but i coded that i am saved all and get all back if i do it

You have to also use storage.get("save") to load the data back in.

In your case, that will return the object "save", with the variable "Money" inside.

Edit: I just looked at the code you provided, and you are passing in the save function, not the object.

That will most certainly cause issues. To fix it, you pass the object into it, and get it roughly like this.

LoadGame = function()
  save = storage.get("save")
  Money.Cash = save.money
end

SaveGame = function()
   save = object money = Money.Cash end
   storage.set("save",save)
end

Please note that only passing variables will make the function actually complete successfully.

This can replace the code in your file "menu" at line 50.

EDIT2: I just looked at it again, and I am honestly baffled. You literally pulled a variable out of your ***, and wondered why it didn't work. Use the LoadGame function as reference.

@confusedcatgirl but i do it in my complete code

maybe cause you are storing "SaveGame" - same name as the function. Could make erros

aaa = function()
  return 1234
end

init = function()
  aaa = "abc"
  print( aaa() )
end

In MicroScript, a variable and a function cannot have the same name.

Post a reply

Progress

Status

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