Page 1 of 1

How to reset SaveData codes in levels?

Posted: Mon Apr 04, 2022 8:54 pm
by Mal8rk
The title says it all

But I'm making a level with a SaveData code, but whenever I play the level and beat it, now I have no way to reset the code

so how can I reset it?

Re: How to reset SaveData codes in levels?

Posted: Tue Apr 05, 2022 5:29 am
by deice
could you be a bit more specific? it's hard to tell whether you want to reset the custom values you've placed inside savedata to their default ones, if you're trying to wipe savedata during play (this can be done by typing "SaveData.clear()" without the quotation marks into the console iirc), or if you're trying to clear progress that was saved during test play (deleting "save0-ext.dat" from the episode folder should take care of this).

Re: How to reset SaveData codes in levels?

Posted: Tue Apr 05, 2022 11:32 am
by Mal8rk
deice wrote:
Tue Apr 05, 2022 5:29 am
could you be a bit more specific? it's hard to tell whether you want to reset the custom values you've placed inside savedata to their default ones, if you're trying to wipe savedata during play (this can be done by typing "SaveData.clear()" without the quotation marks into the console iirc), or if you're trying to clear progress that was saved during test play (deleting "save0-ext.dat" from the episode folder should take care of this).
Yeah, I guess I should've been more specific

I was trying to clear saveData values during play, but thanks for the help

Also, is the console iirc the level's lua file, or is it something else?

Re: How to reset SaveData codes in levels?

Posted: Tue Apr 05, 2022 11:59 am
by deice
POPME wrote:
Tue Apr 05, 2022 11:32 am
Yeah, I guess I should've been more specific

I was trying to clear saveData values during play, but thanks for the help

Also, is the console iirc the level's lua file, or is it something else?
the console can be opened in the tester by pressing tab (iirc stands for "if i recall correctly"). type the statement into it and press enter to execute. if anything breaks after you clear savedata (some scripts don't perform nil checks), closing and reopening the tester should fix the issue.

Re: How to reset SaveData codes in levels?

Posted: Tue Apr 05, 2022 12:59 pm
by Mal8rk
deice wrote:
Tue Apr 05, 2022 11:59 am
POPME wrote:
Tue Apr 05, 2022 11:32 am
Yeah, I guess I should've been more specific

I was trying to clear saveData values during play, but thanks for the help

Also, is the console iirc the level's lua file, or is it something else?
the console can be opened in the tester by pressing tab (iirc stands for "if i recall correctly"). type the statement into it and press enter to execute. if anything breaks after you clear savedata (some scripts don't perform nil checks), closing and reopening the tester should fix the issue.
Well, I pressed tab on the level editor but nothing happened

is there a way to open this without tab?

Re: How to reset SaveData codes in levels?

Posted: Tue Apr 05, 2022 2:02 pm
by deice
POPME wrote:
Tue Apr 05, 2022 12:59 pm
Well, I pressed tab on the level editor but nothing happened

is there a way to open this without tab?
i said "tester" not "editor" i.e. you're meant to press tab while playtesting the level.

Re: How to reset SaveData codes in levels?

Posted: Tue Apr 05, 2022 8:34 pm
by Mal8rk
Well I used SaveData.clear() in the console command, and absolutely nothing happened, unless I'm doing something wrong...

Here's my code, tell me if there's something I should change to make this work:

Code: Select all

function onStart()
	SaveData["Bowser's Castle of Doom.lvlx"] = SaveData["Bowser's Castle of Doom.lvlx"] or {}
	if(SaveData["Bowser's Castle of Doom.lvlx"].cleared == nil) then
		SaveData["Bowser's Castle of Doom.lvlx"].cleared = true
		triggerEvent("level starts")
	else
		if(SaveData.gameCleared == nil) then
			triggerEvent("level cleared")
		end
	end
end

Re: How to reset SaveData codes in levels?

Posted: Wed Apr 06, 2022 10:56 am
by deice
POPME wrote:
Tue Apr 05, 2022 8:34 pm
Well I used SaveData.clear() in the console command, and absolutely nothing happened, unless I'm doing something wrong...

Here's my code, tell me if there's something I should change to make this work:

Code: Select all

function onStart()
	SaveData["Bowser's Castle of Doom.lvlx"] = SaveData["Bowser's Castle of Doom.lvlx"] or {}
	if(SaveData["Bowser's Castle of Doom.lvlx"].cleared == nil) then
		SaveData["Bowser's Castle of Doom.lvlx"].cleared = true
		triggerEvent("level starts")
	else
		if(SaveData.gameCleared == nil) then
			triggerEvent("level cleared")
		end
	end
end
clearing savedata at that point will have no effect because onStart() only triggers once at the very start of the level, obvioulsy before you get to type any console commands in. it seems you haven't quite accurately articulated what effect you actually want to achieve. i assume you want to set "SaveData["Bowser's Castle of Doom.lvlx"].cleared" to nil again? in that case, you have to either manually place some code that does that (anywhere will work, as long as it executes before the given level is loaded) or delete your save file for the episode.

Re: How to reset SaveData codes in levels?

Posted: Wed Apr 06, 2022 12:35 pm
by Mal8rk
deice wrote:
Wed Apr 06, 2022 10:56 am
POPME wrote:
Tue Apr 05, 2022 8:34 pm
Well I used SaveData.clear() in the console command, and absolutely nothing happened, unless I'm doing something wrong...

Here's my code, tell me if there's something I should change to make this work:

Code: Select all

function onStart()
	SaveData["Bowser's Castle of Doom.lvlx"] = SaveData["Bowser's Castle of Doom.lvlx"] or {}
	if(SaveData["Bowser's Castle of Doom.lvlx"].cleared == nil) then
		SaveData["Bowser's Castle of Doom.lvlx"].cleared = true
		triggerEvent("level starts")
	else
		if(SaveData.gameCleared == nil) then
			triggerEvent("level cleared")
		end
	end
end
clearing savedata at that point will have no effect because onStart() only triggers once at the very start of the level, obvioulsy before you get to type any console commands in. it seems you haven't quite accurately articulated what effect you actually want to achieve. i assume you want to set "SaveData["Bowser's Castle of Doom.lvlx"].cleared" to nil again? in that case, you have to either manually place some code that does that (anywhere will work, as long as it executes before the given level is loaded) or delete your save file for the episode.
So let me see if I got it, I have to make a new line in my code where I set the SaveData values of my level to nil again

I'll have to make it like with npcs with "return npc"

Re: How to reset SaveData codes in levels?

Posted: Wed Apr 06, 2022 3:35 pm
by deice
POPME wrote:
Wed Apr 06, 2022 12:35 pm
So let me see if I got it, I have to make a new line in my code where I set the SaveData values of my level to nil again
if that's what you're trying to do, then yes.
POPME wrote:
Wed Apr 06, 2022 12:35 pm
I'll have to make it like with npcs with "return npc"
i don't mean to come off as rude or anything, but it sort of seems like you're just putting code that you found somewhere into your level without actually understanding what it does. i highly recommend you take a step or two back and get a better grasp at lua fundamentals before trying to implement (what at the very least seems to be) some kind of progression system, as this statement above looks quite nonsensical to me in this context.

Re: How to reset SaveData codes in levels?

Posted: Wed Apr 06, 2022 4:21 pm
by Mal8rk
deice wrote:
Wed Apr 06, 2022 3:35 pm
POPME wrote:
Wed Apr 06, 2022 12:35 pm
So let me see if I got it, I have to make a new line in my code where I set the SaveData values of my level to nil again
if that's what you're trying to do, then yes.
POPME wrote:
Wed Apr 06, 2022 12:35 pm
I'll have to make it like with npcs with "return npc"
i don't mean to come off as rude or anything, but it sort of seems like you're just putting code that you found somewhere into your level without actually understanding what it does. i highly recommend you take a step or two back and get a better grasp at lua fundamentals before trying to implement (what at the very least seems to be) some kind of progression system, as this statement above looks quite nonsensical to me in this context.
Ya know what, you're right, I should take the time to understand the fundamentals of luna.lua without just telling people to teach me how to do it.

I'll make an effort to figure the solution to my problem

Update: Yeah, I'm a clear example of what happens when someone is desperate to find solutions without digging deeper

turns out the only thing I had to change was the "gameCleared" bit of the code shown bellow to simply "levelCleared"

Code: Select all

if(SaveData.levelCleared == nil) then
			triggerEvent("level cleared")
Thanks for the suggestions, but after this, I'm done making questions in this forum, I'll start to be more independent since I'm actually learning quite a bit from external sources for lua