Page 1 of 1

Is it possible to make an NPC appear only once.

Posted: Fri Oct 22, 2021 3:22 am
by CerealCat
I want the player to find a Yoshi in one level, but have it only appear once. Even if they leave the level and come back, I don't want it to reappear. Even if they accidentally kill the Yoshi, I don't want it to reappear. Is that possible?

Re: Is it possible to make an NPC appear only once.

Posted: Fri Oct 22, 2021 7:34 am
by deice
put the yoshi in it's own layer, and then put this code into the level's lua file.

Code: Select all

local LAYER_NAME = "test" --name of the yoshi's layer

function onStart()
	if(SaveData.seenYoshiL == true) then
		Layer.get(LAYER_NAME):hide(true)
	end
	
	SaveData.seenYoshiL = true
end
be sure to test this in the episode itself and not the level editor, as the play tester might not maintain SaveData between multiple tests

Re: Is it possible to make an NPC appear only once.

Posted: Fri Oct 22, 2021 5:46 pm
by CerealCat
deice wrote:
Fri Oct 22, 2021 7:34 am
put the yoshi in it's own layer, and then put this code into the level's lua file.

Code: Select all

local LAYER_NAME = "test" --name of the yoshi's layer

function onStart()
	if(SaveData.seenYoshiL == true) then
		Layer.get(LAYER_NAME):hide(true)
	end
	
	SaveData.seenYoshiL = true
end
be sure to test this in the episode itself and not the level editor, as the play tester might not maintain SaveData between multiple tests
Thanks, works flawlessly!

Re: Is it possible to make an NPC appear only once.

Posted: Sun Nov 07, 2021 5:58 am
by MrDoubleA
deice wrote:
Fri Oct 22, 2021 7:34 am
put the yoshi in it's own layer, and then put this code into the level's lua file.

Code: Select all

local LAYER_NAME = "test" --name of the yoshi's layer

function onStart()
	if(SaveData.seenYoshiL == true) then
		Layer.get(LAYER_NAME):hide(true)
	end
	
	SaveData.seenYoshiL = true
end
be sure to test this in the episode itself and not the level editor, as the play tester might not maintain SaveData between multiple tests
Side note: the tester DOES keep SaveData between tests. However, it will only maintain it between sessions if it was saved (by beating a level or what have you).