MV [YANFLY Event Spawner] $gameMap.LastSpawnedEventID() is addressing ALL previous SpawnedEvent and not only the last one in a situation

Hi everyone, and in particular @Yanfly if you are available.

I'm having a particular issue :

Code:
$gameMap.event($gameMap.LastSpawnedEventID()).event().note = $gameMap.event(this.eventId()).event().note

With this code, I try to copy the data stored in the note tag of the spawner into the note tag of the spawned event.

This works, for the first one. Then if an other event spawner do the same, it will replace the notes of first AND the second spawned event.
If I do it third time, it will also replace all previous notes of all previous spawned event.

I do it in an autorun event to be sure.

The $gameMap.LastSpawnedEventID() in each spawner is working fine, since I put text box to control all the value, so at first, it works, then after, everything change like said before.

I tried using transitional variable, it's useless because it works fine with one line, but I wanted to be sure.
I'm not familiar with the plugin, so this might not help, but what if you do it without the autorun? Autorun loops at the end of the event, so my thinking is that it might be tackling the last spawned event...and then when it loops it hits the last spawned event before that, and so on. Again, no idea if this will help, but hopefully it's a good place to start testing.
I put an "erase event" at the end of this event, but, you know what, I will test something.

EDIT : Holy , "erase event" dont erase the event >< !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

EDIT2 : Hmmmm, but I was able to move, so this mean the autorun stopped at a point, right ?

EDIT3 : How can I stop the event and prevent him to apply it every frame @schvanckque ?
"erase event" dont erase the event
in case of default events, erase event should remove the event from memory but not from the static mapfile, causing it to reload on map reload.

your problem most likely comes from whatever workaround is used to keep the spawned events.
because those spawned events CANNOT go into the (static) map file like all other events - only the editor can write into that file.
so whatever event spawner you use, it has to create a different place to store and handle the spawned events, and connect that to the regular events for everything to work as normal.

and if that has a problem it might circumvent any other event function.
so take a step back and check your event spawner for compatibility with your other event plugins, and perhaps try one of the alternate event spawners.
I think Andar's advice probably speaks best to the root of the problem. As for 'erase event' that does only remove the event until the map is loaded again (like if you leave the screen and come back to it) so for anything you only want to happen one time, it's best to stick a self switch on the event and turn it on at the end of whatever you want that event to do, then just set up a second page with that SS as the condition and leave everything else blank (or not, if you want it to do something different).
Hi everyone, and in particular @Yanfly if you are available.

I'm having a particular issue :

Code:
$gameMap.event($gameMap.LastSpawnedEventID()).event().note = $gameMap.event(this.eventId()).event().note

With this code, I try to copy the data stored in the note tag of the spawner into the note tag of the spawned event.

This works, for the first one. Then if an other event spawner do the same, it will replace the notes of first AND the second spawned event.
If I do it third time, it will also replace all previous notes of all previous spawned event.

I do it in an autorun event to be sure.

The $gameMap.LastSpawnedEventID() in each spawner is working fine, since I put text box to control all the value, so at first, it works, then after, everything change like said before.

I tried using transitional variable, it's useless because it works fine with one line, but I wanted to be sure.
I'm technically on a forum break right now but since I *can* answer this, I shall.

The reason this is happening is that the event() function accesses the event data behind the Game_Event instance, which is where it gets its note from. This is part of the JSON file for the map. When you spawn an event, although it's a new Game_Event with its own ID, the event data behind it is the same as the original. So if you modify the note of one of those events, you alter it for every event that used that data, because it isn't creating a new data entry for the spawned one.

So really, your spawned events should *already* have the same note as the spawner does. Do yours not?
But I cant use a self switch, since if I exit the room, the event will not spawn anymore.

Since I need them only one time when the map load, the erase event seems to be perfect.

To figured out it was not working, I just added a text box after the "erase event", and this text box was still working.

The full story is that I already did that, 28th december 2021, and I accidentally deleted my project and didnt think to backup it...

I dont remember how I used it, I only took a note on a notepad "self var are the key" >.> ... But it's not working with Yanfly Self Var neither with Eli Self Var plugins.

EDIT : I dont know @Trihan, something in looping and I dont know how to stop it until the map reload.
But I cant use a self switch, since if I exit the room, the event will not spawn anymore.

Since I need them only one time when the map load, the erase event seems to be perfect.

To figured out it was not working, I just added a text box after the "erase event", and this text box was still working.

The full story is that I already did that, 28th december 2021, and I accidentally deleted my project and didnt think to backup it...

I dont remember how I used it, I only took a note a notepad "self var are the key" >.> ...
The reason for that is that "erase event" just flips an internal flag called _erased on the event object; this doesn't stop the rest of the page from executing. It only takes effect afterwards one the interpreter is done with the event, and then the update loop stops looking at that event since the flag is true.
Ha.

So the loop was not my issue after all... Return to starting point.

EDIT : But if it's not a loop which give the note to every event, what is it ?
Ha.

So the loop was not my issue after all... Return to starting point.

EDIT : But if it's not a loop which give the note to every event, what is it ?
The data that constructs those events comes from the same json object. When you edit the note, you're editing the note on the source data. Every event that came from that data will reflect the note change because they don't have a note of their own.
Okay, so, you think the first time, I probably didnt use this portion of code, I probably used an other method to give this data to the spawned events.

It's possible, because of the note I took in my notepad.

But every try about talking to the spawned even with the command gave with Yanfly Self Var and Eli Self Var failed.
Example :
Step 1 : take the number of the last spawned event and put it in a transitional global var.
This fail here.
The next Step 2 would be to give this data to the local var of a distant event, but it fail before it.
What is it you're actually trying to accomplish here? Knowing that may be more helpful than knowing how what you've tried isn't doing what you want.
So I'm curious about what exactly this is all supposed to do, functionally, in the game. What are you trying to store in the note of the spawned events? Is it something that has to be a note, such as notetags provided by certain plugins? Or is it a value that can just be stored and retrieved from a self variable (variables can include strings, not just numbers), in which case perhaps that's what your note-to-self meant by "self var are the key"?
If I exit the room, I clear all spawned event to avoid bugs.
If I enter again, I want all my events to spawn if they are allowed to do.

And by allowed to do, I mean "if a global var is set to allow that".

To set this global var, I need my spawned event to know this data (The number of the global variable assigned to them, itinialiy stored in the note of the spawner), and the only way for them to know it is that daddy give them.

I tried 2 things to tell them : writing in their note, and writing in their local var (with a plugin).
@Nemesis666 Can you show screenshots of the template event's pages? (And any other event that might be involved in spawning/despawning/setting values for these spawned events)
that is still not answering the question of what you want to achieve - again you only tell us how you want to achieve the unknown something.

What are those spawned events? enemies to fight, furniture in the player base, crops to grow in the field?
why do you have to delete the events at all on leaving?
what is the player supposed to see on entering the map?
Oh, the full story is super complicated to explain :
There are passerby(ies ?) which are waiting for you to come to talk to them, their skin are randomly chosen, so you have to kill them if you change a room, or, if you come back, no one gave them a skin (Since the spawner can only create an event if the place/case/space is empty).

After talking to them, you set a global var to 1 to say "someone talked to me, I can leave", if you dont, they will come back at the next reload of the map. This var is linked to the spawer, he is the one giving the intel to his child.
and the other answers? like why do you have to delete the spawned events on leaving the map?

because this would be super-easy to handle if you don't delete the spawned events.

and could you please give more background on the why? because this is a case where it should be considered to be handled by a custom plugin, as again this would be extremely easy to handle if you have a custom plugin instead of trying to patch a patch for some other function with a fix that is for still some other workaround.
a custom plugin would only have to handle the storage itself very easily instead all this assignment hell.
I answered :
Code:
 their skin are randomly chosen, so you have to kill them if you change a room, or, if you come back, no one gave them a skin (Since the spawner can only create an event if the place/case/space is empty).

Okay, so, listen, I found out where my issue was about Self Var :

Code:
$gameVariables.setValue(35, $gameVariables.value(32));

<= this dont work for local var, I had to use the incoporated system to communicate the value.

So, I was able to transfer the data from the daddy to the children, then the children was able to read the data, this create these pages :

Children (Rest of the page is pointless here) :
RPG Maker Children Page.png

Daddy :
RPG Maker Daddy Page.png


The interface is in french but it's easy to understand 😛 .
So is that your issue fixed now then?

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-event-spawner-gamemap-lastspawnedeventid-is-addressing-all-previous-spawnedevent-and-not-only-the-last-one-in-a-situation.146181/