MZ Self Variables Inside Spawned Events

So I'm trying to do a thing...

I have a trash can event which is spawned in from a template map using an event spawner for MZ. The player can spawn these trash cans in at their own discretion. Meaning I need to account for the possibility of there being an unknown amount at any given time. This lead me to self variables. I wanted each spawned event trash can to fill up and have the ability to automatically check its own self variable to determine its capacity and then display it to the player in a show text command when it is full.

The few self variable plugins I have found require each event to still have its own Self Variable preset on a global variable. Example: Variable ID# 001 can be set to Self Variable 1 and can be then interacted with as a self variable remotely. However I quickly realized this isnt what I needed.

So when I spawn in more than one trash can both with the same eventing which is checking for example self variable 15. Every change I make to self variable 15 is then matched to every trash can ultimately making this self variable not so 'self' again. I'm at a loss. I feel like this should be doable. Maybe I've just been up too long and I can't think clearly lol. Either way any advice would be helpful. If what I'm asking is crazy feel free to let me know XD
Tried with Yanfly's self variables? I think it should work with this as you said.

Hi there!

If I understood you well, I believe my self variable plugin can do the trick.
It will indeed use a regular variable and turn it into a self variable. But, it works similar to the self switch, which means, each event will have its own data for that same variable, which is under the hood, stored as an object with the key property combining the map id, event id, and the variable id.
So I guess it will work as you want.

Self Variables

You will need my Core plugin to use it too:

[EDIT] Also, you can fully use the plugin without any plugin command at all. it is fully integrated with event commands. But there is plugin command if you want to.
What Event Spawner are you using? If this Plugin was written properly, it should not cause any troubles with Self Switches. Self Switches are stored in a global container, not the event itself. The only thing that the Plugin needs to implement, is to assign a new unique Event Id to the Event. If the Plugin does not do that, it's a bad design IMO.
What Event Spawner are you using? If this Plugin was written properly, it should not cause any troubles with Self Switches. Self Switches are stored in a global container, not the event itself. The only thing that the Plugin needs to implement, is to assign a new unique Event Id to the Event. If the Plugin does not do that, it's a bad design IMO.
Not sure it changes anything, but he/she talks about self variables, not self switches.
Not sure it changes anything, but he/she talks about self variables, not self switches.
Oh I see. Still I want to know the Plugins he's using. If all those Plugins work as I described, there should be no problems.
If you're using VS's Event Manager, you can't interact with the Self-Variables via normal variable processing, you need to use Plugin Commands. You'll need to be running background checks to assess how many trash cans are spawned, and you can use Javascript to get things like last/first spawn ID. Otherwise leaving it as '0' will be the event itself (ie the player places trash in via an action button trigger, it'll increase its own variable).

1637756110947.png


Otherwise it should all work as specified. You need to use the plugin call for all instances of changing the variable, but the conditions page can be set up as normal:
1637756210445.png


I feel the more accessible method for this would be to have an upper limit of trash cans and instead use a 'Copy' function, so you know exactly what Event IDs the trash cans can occupy at any given time rather than having to use JS to grab the spawned event. That way you can run through your list, check if the event is in an 'active' state, and add the variable to the event ID given.

(The logic in this last bit should carry to any plugin you end up using though.)
Hi there!

If I understood you well, I believe my self variable plugin can do the trick.
It will indeed use a regular variable and turn it into a self variable. But, it works similar to the self switch, which means, each event will have its own data for that same variable, which is under the hood, stored as an object with the key property combining the map id, event id, and the variable id.
So I guess it will work as you want.

Self Variables

You will need my Core plugin to use it too:

[EDIT] Also, you can fully use the plugin without any plugin command at all. it is fully integrated with event commands. But there is plugin command if you want to.
Your plugin was the first I tried actually lol. Since I'm already using some of your other ones. Love your stuff!

Anywayssss... when i tried to test your plugin without ANY spawning using two manually place events and having one on action button set the self variable to 5 and the other set to add 5 instead. Both cans will then display the variable using \v[]. When I activate the one event it successfully sets the self variable to 5 and displays it as such. However when I go to the next one to add the 5 and then go back to the previous I find that both are synced. Even though they shouldn't be.
Oh I see. Still I want to know the Plugins he's using. If all those Plugins work as I described, there should be no problems
No worries! I should have done this earlier my bad. Here is a screenshot of my plugin list :]

1637785092627.png
If you're using VS's Event Manager, you can't interact with the Self-Variables via normal variable processing, you need to use Plugin Commands. You'll need to be running background checks to assess how many trash cans are spawned, and you can use Javascript to get things like last/first spawn ID. Otherwise leaving it as '0' will be the event itself (ie the player places trash in via an action button trigger, it'll increase its own variable).

View attachment 207660

Otherwise it should all work as specified. You need to use the plugin call for all instances of changing the variable, but the conditions page can be set up as normal:View attachment 207661

I feel the more accessible method for this would be to have an upper limit of trash cans and instead use a 'Copy' function, so you know exactly what Event IDs the trash cans can occupy at any given time rather than having to use JS to grab the spawned event. That way you can run through your list, check if the event is in an 'active' state, and add the variable to the event ID given.

(The logic in this last bit should carry to any plugin you end up using though.)

Im using Ritters Event spawner only because it was the only one that gave me the exact compatibility with MZ3D as well as pathfinding plugins I've been experimenting with..(MZ3D can be touchy with that).

Ritters starts the spawn event ID's at 1000. Im already using it to spawn customer NPC's and I have event ID's 1000 to about 1,150 reserved for these NPC's and a conditional running prior to the spawn command to ensure the max capacity isnt over 150 and if it is start despawning a random event id between 1000 and 1500. I want to essentilly do the same thing but let the player control it via placing items from inventory like the trash can etc. I could limit like you said and reserve some events like i did with the NPC's however if I can't get the self variable plugins to work properly it wouldnt mattter much anyways.
I actually tried your plugin first XD

So far this has all been very helpful. And I think we can solve what I'm doing wrong.

I'm also using Ritters Event Spawner. (Should have included that in the original post)

This is what happens when I try to create a test self variable on two different static events placed without spawning.

Your plugin was the first I tried actually lol. Since I'm already using some of your other ones. Love your stuff!

Anywayssss... when i tried to test your plugin without ANY spawning using two manually place events and having one on action button set the self variable to 5 and the other set to add 5 instead. Both cans will then display the variable using \v[]. When I activate the one event it successfully sets the self variable to 5 and displays it as such. However when I go to the next one to add the 5 and then go back to the previous I find that both are synced. Even though they shouldn't be.
Here are some images of both manually place test events changing the same self variable:

1637785714253.png

1637785736114.png


And here was my last attempt at doing the spawned one I need:

1637785775266.png


And last here is my variables list showing the two that were reserved.

1637785900187.png


PS Thanks again for your help I really appreciate it!
Here are some images of both manually place test events changing the same self variable:


PS Thanks again for your help I really appreciate it!
Hi!

Well, it is supposed to work. But I don't know how the Ritter plugin works, but I manage to do that with the Triacontane Event Spawner/Template and it works.

Instead of using the event ID in the plugin command, try to use 0(Just like you are doing with the MAP Id).
0 will give you automatically the event id where the plugin command is being called. Since you are using Spawned events, you really need to use 0 in the event ID, since as they are spawned, their id is probably dynamic.

An alternative way is to do like below(which is the same as you are doing with the plugin command, but with fewer event lines):

self example.png


As long as your variable has the "SV:" it will work fully integrated with event commands.

[EDIT] The last screenshot is showing how the plugin stores the self variable data:
114 = Map id
11 = Event Id
2 = Var Id
So, they are combined and create a unique id for that self variable: "114,11,2".
Hi!

Well, it is supposed to work. But I don't know how the Ritter plugin works, but I manage to do that with the Triacontane Event Spawner/Template and it works.

Instead of using the event ID in the plugin command, try to use 0(Just like you are doing with the MAP Id).
0 will give you automatically the event id where the plugin command is being called. Since you are using Spawned events, you really need to use 0 in the event ID, since as they are spawned, their id is probably dynamic.

An alternative way is to do like below(which is the same as you are doing with the plugin command, but with fewer event lines):

View attachment 207777

As long as your variable has the "SV:" it will work fully integrated with event commands.

[EDIT] The last screenshot is showing how the plugin stores the self variable data:
114 = Map id
11 = Event Id
2 = Var Id
So, they are combined and create a unique id for that self variable: "114,11,2".
Ok this makes sense to me I'm going to try this again only using 0 for eventID's. I'll try it first with just regular events and if I can get that work Ill move on to trying it with the spawned.
Hi!

Well, it is supposed to work. But I don't know how the Ritter plugin works, but I manage to do that with the Triacontane Event Spawner/Template and it works.

Instead of using the event ID in the plugin command, try to use 0(Just like you are doing with the MAP Id).
0 will give you automatically the event id where the plugin command is being called. Since you are using Spawned events, you really need to use 0 in the event ID, since as they are spawned, their id is probably dynamic.

An alternative way is to do like below(which is the same as you are doing with the plugin command, but with fewer event lines):

View attachment 207777

As long as your variable has the "SV:" it will work fully integrated with event commands.

[EDIT] The last screenshot is showing how the plugin stores the self variable data:
114 = Map id
11 = Event Id
2 = Var Id
So, they are combined and create a unique id for that self variable: "114,11,2".
Ok so I've come to the conclusion that something somehow is breaking any self variable plugin
I'm using. I created the two events just like you said to do. See below:


Trash Can Test Event1
1637813660173.png




Trash Can Test Event2
1637813704649.png



i click one trash can and add an amount to the variable. I then display that var just to be sure it worked. It does. Next I go to second trash can event and without ADDING ANYTHING I JUST CHECK THE VAR and it says the same amount as the first when it should say zero since i never changed it.

Step One: Add 10 to first trash can using SV: trashCanCapacity
1637814024744.png



Step 2 Display SV: trashCanEvent on second trash can. It should say zero...buts still synced with the global var.
1637814137165.png
Ok I think I'm getting somewhere. After messing around with the two events above i discovered that the self var isn't updating properly. For example:

After adding 5 to self variable for test event1 checking the variable for event2 will show 5 as well...UNTIL you make any sort of change to event2's self variable. THEN it properly shows its self variable. BUT the issue just goes on back forth between the two events. Im assuming there is something conflicting. Im gonna test my plugins to find out. Im hoping its not Ritters Event Spawner because its the only one that works the way I need it too. However it IS the only other plugin I have afaik that effects variables.
OKAY! I FOUND A WORK-AROUND/SOLUTION TO THE ABOVE ISSUE!

The self variable of the event you want to check needs to be MANUALLY updated after adjusting the same self variable in another event. Simply ADD ZERO to the self variable right before displaying it.

1637824519500.png



I'm not sure if this is the way the plugin is intended to function. If not this seems to be a fix 'for now'. With things like this if it IS a bug or something it could pop up again somewhere in the future in a less fixable way.

PS I couldn't delete Ritters Spawn Event to test compatibility. It's tied to too many things in my game and when I remove it my project crashes on launch.
Hi @OktoberLove !

I tested here a lot, and finally, I think I know what the problem is.
It seems that the integrated Self Variables with the event commands will not work at all, at least with the way I set it.
And that integration is causing the problem(and a lot of other problems besides this one you are showing to me).

I let you know when I fix it!

[EDIT] For now you can download the fixed version (3.0.1). I removed the event commands integration for now, but the plugin command will work just fine now.

To get a self variable value you can use script calls:

• Getting self variable values:
JavaScript:
Current event -> this.selfVariableValue(varId) OR this.getSv(varId)
Other events/map -> $gameVariables.selfValue([mapId, eventId, varId])

• Changing self variable values:
JavaScript:
Current event -> this.setSelfVariableValue(varId, value) OR this.setSv(varId, value)
Other events/maps -> $gameVariables.setSelfValue([mapId, eventId, varId], value)
Hi @OktoberLove !

I tested here a lot, and finally, I think I know what the problem is.
It seems that the integrated Self Variables with the event commands will not work at all, at least with the way I set it.
And that integration is causing the problem(and a lot of other problems besides this one you are showing to me).

I let you know when I fix it!

[EDIT] For now you can download the fixed version (3.0.1). I removed the event commands integration for now, but the plugin command will work just fine now.

To get a self variable value you can use script calls:

• Getting self variable values:
JavaScript:
Current event -> this.selfVariableValue(varId) OR this.getSv(varId)
Other events/map -> $gameVariables.selfValue([mapId, eventId, varId])

• Changing self variable values:
JavaScript:
Current event -> this.setSelfVariableValue(varId, value) OR this.setSv(varId, value)
Other events/maps -> $gameVariables.setSelfValue([mapId, eventId, varId], value)
Perfect thank you so much seriously! I look forward to your update! 😀

Original thread: https://forums.rpgmakerweb.com/threads/self-variables-inside-spawned-events.142418/