Page 1 of 1

Removing/Replacing NPC's from a seperate levels.

Posted: Sat Apr 18, 2020 11:28 am
by DrMekar
Hi,

though I wondered if it would be possible somehow to permently remove and/or replace a NPC in level if it isen't played. Here would be an Example:
Image
This Castle Employee Bob appears in the Mushroom Castle a Level with kind of a Hub Function in terms of Star Unlocks and looking
at Information and so on. He reappears in World 4 were he catches a scar, but survives. After the Player finished the level I'd like Bob
to use another Model over a diffrent NPC (Because of the Scar) and have a New Dialogue.

Would that be possible, even without the use of Stars?

Thanks in Advance

Re: Removing/Replacing NPC's from a seperate levels.

Posted: Sat Apr 18, 2020 11:31 am
by Emral
You could use SaveData to store that information, and then show/hide a layer depending on the state of that savedata variable.

Re: Removing/Replacing NPC's from a seperate levels.

Posted: Sat Apr 18, 2020 12:03 pm
by DrMekar
Enjl wrote:
Sat Apr 18, 2020 11:31 am
You could use SaveData to store that information, and then show/hide a layer depending on the state of that savedata variable.
Okay, so it would work, Thanks.

Just gotta find out how this works now :?

Re: Removing/Replacing NPC's from a seperate levels.

Posted: Sat Apr 18, 2020 12:06 pm
by Emral
DrMekar wrote:
Sat Apr 18, 2020 12:03 pm
Enjl wrote:
Sat Apr 18, 2020 11:31 am
You could use SaveData to store that information, and then show/hide a layer depending on the state of that savedata variable.
Okay, so it would work, Thanks.

Just gotta find out how this works now :?
https://docs.google.com/document/d/1uOd ... vzsktm6utv

It's simply a table that saves when SMBX saves.

Re: Removing/Replacing NPC's from a seperate levels.

Posted: Sat Apr 18, 2020 1:32 pm
by DrMekar
Enjl wrote:
Sat Apr 18, 2020 12:06 pm
DrMekar wrote:
Sat Apr 18, 2020 12:03 pm
Enjl wrote:
Sat Apr 18, 2020 11:31 am
You could use SaveData to store that information, and then show/hide a layer depending on the state of that savedata variable.
Okay, so it would work, Thanks.

Just gotta find out how this works now :?
https://docs.google.com/document/d/1uOd ... vzsktm6utv

It's simply a table that saves when SMBX saves.
Ah, okay. So in this case it would be:

Code: Select all

SaveData.hasBeatenLevel = true
I though have only worked with NPCs Data on a level base, so I'm
not sure how to connect the SaveData with the destined level. (Which
would be "Mushroom Castle.lvlx" in the Episode Folder.

Re: Removing/Replacing NPC's from a seperate levels.

Posted: Sat Apr 18, 2020 1:50 pm
by Emral
DrMekar wrote:
Sat Apr 18, 2020 1:32 pm

I though have only worked with NPCs Data on a level base, so I'm
not sure how to connect the SaveData with the destined level. (Which
would be "Mushroom Castle.lvlx" in the Episode Folder.
If it's a one-time flag I wouldn't even go by the level name... just name it like, SaveData.bobEyepatch and set it to true when the level in question is beaten, and check if it's true in onStart of the hub level where the layer needs to be swapped.

Re: Removing/Replacing NPC's from a seperate levels.

Posted: Sat Apr 18, 2020 3:12 pm
by DrMekar
Enjl wrote:
Sat Apr 18, 2020 1:50 pm
DrMekar wrote:
Sat Apr 18, 2020 1:32 pm

I though have only worked with NPCs Data on a level base, so I'm
not sure how to connect the SaveData with the destined level. (Which
would be "Mushroom Castle.lvlx" in the Episode Folder.
If it's a one-time flag I wouldn't even go by the level name... just name it like, SaveData.bobEyepatch and set it to true when the level in question is beaten, and check if it's true in onStart of the hub level where the layer needs to be swapped.
Okay, Thanks, though I might possibly use this in multiple occasions. For Example after World 4, Bob gets a Scar and maybe someother NPC or so all in one Event and after beating the main Story or something, confetti (BGOs) get added to the Castle How would I define that?

Thanks so far by the way :)

Re: Removing/Replacing NPC's from a seperate levels.

Posted: Sat Apr 18, 2020 3:45 pm
by Emral
DrMekar wrote:
Sat Apr 18, 2020 3:12 pm
Enjl wrote:
Sat Apr 18, 2020 1:50 pm
DrMekar wrote:
Sat Apr 18, 2020 1:32 pm

I though have only worked with NPCs Data on a level base, so I'm
not sure how to connect the SaveData with the destined level. (Which
would be "Mushroom Castle.lvlx" in the Episode Folder.
If it's a one-time flag I wouldn't even go by the level name... just name it like, SaveData.bobEyepatch and set it to true when the level in question is beaten, and check if it's true in onStart of the hub level where the layer needs to be swapped.
Okay, Thanks, though I might possibly use this in multiple occasions. For Example after World 4, Bob gets a Scar and maybe someother NPC or so all in one Event and after beating the main Story or something, confetti (BGOs) get added to the Castle How would I define that?

Thanks so far by the way :)
The same way! You just need to set the boolean value and name the variable something that indicates what it will do. Your cases all come down to:
1) In the code for a specific event (such as beating a level), set a savedata variable
2) In the code for a different level, read the save data variable and see if it's true. If it's true, call an event that triggers layers (triggerEvent("myEventForThisVariable"))

Re: Removing/Replacing NPC's from a seperate levels.

Posted: Sat Apr 18, 2020 4:13 pm
by DrMekar
Enjl wrote:
Sat Apr 18, 2020 3:45 pm
DrMekar wrote:
Sat Apr 18, 2020 3:12 pm
Enjl wrote:
Sat Apr 18, 2020 1:50 pm

If it's a one-time flag I wouldn't even go by the level name... just name it like, SaveData.bobEyepatch and set it to true when the level in question is beaten, and check if it's true in onStart of the hub level where the layer needs to be swapped.
Okay, Thanks, though I might possibly use this in multiple occasions. For Example after World 4, Bob gets a Scar and maybe someother NPC or so all in one Event and after beating the main Story or something, confetti (BGOs) get added to the Castle How would I define that?

Thanks so far by the way :)
The same way! You just need to set the boolean value and name the variable something that indicates what it will do. Your cases all come down to:
1) In the code for a specific event (such as beating a level), set a savedata variable
2) In the code for a different level, read the save data variable and see if it's true. If it's true, call an event that triggers layers (triggerEvent("myEventForThisVariable"))
Thanks again. I still two had two Questions though:

1. What do I need to do in the level which complication causes the Things to change in the other level?

2. How do I enter the name of the level in the SaveData Function?

Re: Removing/Replacing NPC's from a seperate levels.

Posted: Sat Apr 18, 2020 4:54 pm
by Emral
DrMekar wrote:
Sat Apr 18, 2020 4:13 pm

Thanks again. I still two had two Questions though:

1. What do I need to do in the level which complication causes the Things to change in the other level?

2. How do I enter the name of the level in the SaveData Function?
1. Set the savedata variable. How you do it is up to you. onEvent, onMessageBox, a conditional in onTick... just trigger the piece of code when you want it to happen.
2. With Level.filename() you can get the filename of the level as a string, but I advised against that earlier because you can't really access any random level's filename from another level without keeping a table of all of them which you manually keep up to date.

Re: Removing/Replacing NPC's from a seperate levels.

Posted: Sat Apr 18, 2020 5:19 pm
by DrMekar
Enjl wrote:
Sat Apr 18, 2020 4:54 pm

2. With Level.filename() you can get the filename of the level as a string, but I advised against that earlier because you can't really access any random level's filename from another level without keeping a table of all of them which you manually keep up to date.
Is there a better way to do it?

Re: Removing/Replacing NPC's from a seperate levels.

Posted: Sat Apr 18, 2020 5:22 pm
by Emral
DrMekar wrote:
Sat Apr 18, 2020 5:19 pm
Enjl wrote:
Sat Apr 18, 2020 4:54 pm

2. With Level.filename() you can get the filename of the level as a string, but I advised against that earlier because you can't really access any random level's filename from another level without keeping a table of all of them which you manually keep up to date.
Is there a better way to do it?
To do what? What's the end goal here?

Re: Removing/Replacing NPC's from a seperate levels.

Posted: Sat Apr 18, 2020 5:32 pm
by DrMekar
Enjl wrote:
Sat Apr 18, 2020 5:22 pm
DrMekar wrote:
Sat Apr 18, 2020 5:19 pm
Enjl wrote:
Sat Apr 18, 2020 4:54 pm

2. With Level.filename() you can get the filename of the level as a string, but I advised against that earlier because you can't really access any random level's filename from another level without keeping a table of all of them which you manually keep up to date.
Is there a better way to do it?
To do what? What's the end goal here?
To activate certain Events in the Mushroom Castle.lvlx when another selected level is beaten.
In this Case the first one would be to change the Layout of the Castle when the last level of World
4 is finished. There would be an Event in Mushroom Castle.lvlx not activated when you visit it normally
the first time or any other time as long as World4-Aftermath.lvlx hasen't been completed. If this this level
is beaten, the Event in Mushroom Castle.lvlx would be triggered and stay activated forever, since World 4-Aftermath.lvlx
will logically forever be completed atleast once after that.

Sorry, if it mind've not missed something, so that's it what I want to do.

Re: Removing/Replacing NPC's from a seperate levels.

Posted: Sat Apr 18, 2020 5:49 pm
by Emral

Code: Select all

LEVEL A

function onEvent(eventName)
	if eventName == "levelbeaten" then
		SaveData.applyChangesFromThisLevel = true
	end
end


LEVEL B
function onStart()
	if SaveData.applyChangesFromThisLevel then
		triggerEvent("executeChangesInLevelBasedOnThingThatHappened")
	end
end
All you describe can be done by using some variation of this code which I think I've exhausted all possibilities of repeating at this point.

Re: Removing/Replacing NPC's from a seperate levels.

Posted: Sat Apr 18, 2020 5:56 pm
by DrMekar
Enjl wrote:
Sat Apr 18, 2020 5:49 pm

Code: Select all

LEVEL A

function onEvent(eventName)
	if eventName == "levelbeaten" then
		SaveData.applyChangesFromThisLevel = true
	end
end


LEVEL B
function onStart()
	if SaveData.applyChangesFromThisLevel then
		triggerEvent("executeChangesInLevelBasedOnThingThatHappened")
	end
end
All you describe can be done by using some variation of this code which I think I've exhausted all possibilities of repeating at this point.
Ah, thanks alot :)

And sorry for all this Questions.