Does anyone know how to reset variables saved via storage?
I'm working on a project… I used storage to save my variables… Now, to check that everything is correct in the code during its first execution, I need to reset the saved variables so that the project doesn't retain the choices already made. Does anyone know how to do this?
man i've had this same problem, hope you find it
You can just do
variable = 0 // or any other default value
I know this function is mainly used to store the variable and that it can be reset by assigning it the value 0, but I was wondering if there was a function that could delete all stored variables at once. If not, thanks anyway.
Well, now that you've brought this up again, I was thinking, and you could use an object in storage:
save = object
level = 4
stage = 3
end
storage.set("save",save)
Now, if you want to delete everything saved, you could simply set that simple value to false
storage.set("save",false)
And to set default values, then every time the game starts, check if storage.get("save") exists or not; if it doesn't exist, then set the default values:
// Default values
local save_default = object
level = 0
stage = 0
end
// Check if anything is already saved in the game
local save_get = storage.get("save")
if save_get then
// If it exists, then use the previously saved data
save = save_get
else
// If it does not exist, use the default values
save = save_default
end
The variable save will be the object used each time you want to review the current data that you will save later
if you have a save mechanic button you can just copy and paste that but instead of it saving your current stats it could save the lowest values for instance
score = 100
// this is the saving button
if b.id = "1" and mouse.press then
storage.set("score", score)
this is what your save button would do but if you make a reset button it would look like this
score = 100
// this is the reset button
if b.id = "2" and mouse.press then
storage.set("score", 0)
hope that helps