Is it possible to make an NPC appear only once.

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

CerealCat
Fighter Fly
Fighter Fly
Posts: 31
Joined: Thu Jul 11, 2019 5:31 pm
Flair: twitch.tv/mscerealcat
Pronouns: she/they
Contact:

Is it possible to make an NPC appear only once.

Postby CerealCat » Fri Oct 22, 2021 3:22 am

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?

deice
Volcano Lotus
Volcano Lotus
Posts: 596
Joined: Fri Jul 23, 2021 7:35 am

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

Postby deice » 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

CerealCat
Fighter Fly
Fighter Fly
Posts: 31
Joined: Thu Jul 11, 2019 5:31 pm
Flair: twitch.tv/mscerealcat
Pronouns: she/they
Contact:

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

Postby CerealCat » Fri Oct 22, 2021 5:46 pm

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!

MrDoubleA
Ripper II
Ripper II
Posts: 394
Joined: Mon Aug 20, 2018 7:02 am
Flair: How much munchers?

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

Postby MrDoubleA » Sun Nov 07, 2021 5:58 am

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).


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari