Event Page Order Help

So I have made progress on creating a farming system in my game similar to Harvest Moon, Stardew Valley, etc, but I am now stuck on one very simple thing. I'm probably over thinking it, but whenever I update my self variables for the death counter (essentially if the crop is not watered, the death variable is subtracted by 1), I can't make it stop. What I mean by this is I can have the plant died if water, but if I spawn new seeds/plants after one plant dies, it will spawn as a dead plant. I have figured I would need to change how the death counter is acquired, but I'm unsure if it needs to be a positive or negative integer. I'm using the Yanfly event foraging tutorial as my guide, so if you need to see the respawn day cycler event, I can share it. Though I did compress it to make all of the lines fit (I used slightly more than the 12 lines MV allows, and I used a javascript compresser someone recommended).


Screen Shot 2023-05-03 at 2.29.08 PM.png

This is my spawn start event. I have moved it around to different event pages, but it either gets stopped by the death page, or this event page stops the death page.

Screen Shot 2023-05-03 at 2.29.10 PM.png

This is the plant death page after it reaches < 0 in the self variable.

Screen Shot 2023-05-03 at 2.29.12 PM.png

This is the event that would be just seeds on the dirt plot.
Screen Shot 2023-05-03 at 2.29.14 PM.png

This is my watered seeds event page.
Screen Shot 2023-05-03 at 2.29.15 PM.png

This would be the second growth stage/sprout stage of the plant.
Screen Shot 2023-05-03 at 2.29.17 PM.png

And this is the second stage watered event.

I would like to add a third stage dry and watered event, but it would require to get everything else in order. I just need to know how to stop the death event page or the spawn event page from overtaking each other, and to stop the death event page from spawning when I place new seeds down to grow.

JavaScript:
mapId=$gameVariables.value(18);var eventId=$gameVariables.value(19),varId=26,deathId=30,harvestId=31,value=this.getSelfVariableValue(mapId,eventId,varId),death=this.getSelfVariableValue(mapId,eventId,deathId),harvest=this.getSelfVariableValue(mapId,eventId,harvestId);value<=0&&(death-=1),0<value&&(harvest-=1),0<value&&--value,this.setSelfVariableValue(mapId,eventId,varId,value),this.setSelfVariableValue(mapId,eventId,deathId,death),this.setSelfVariableValue(mapId,eventId,harvestId,harvest);

The code above is my compressed javascript where the variables are updated through a bed common event.
varId is my variable for if the plant is watered or not, var deathId/ self variable 30 is my death counter variable that is updated, and var harvestId/ self variable 31 is my "days until ready to harvest" variable that is updated. Any and all help is appreciated!! I know I'm probably overcomplicating things or making a silly mistake, but it helps to have a second opinion/a second pair of eyes for this! I will also happily put your username in my game credits for helping me since this is such a crucial aspect for my game!
A few things:

- It would be very useful to note that you appear to be using HimeWorks' Custom Page Conditions and link to that plugin. I'm presuming that from Googling.

(I used slightly more than the 12 lines MV allows, and I used a javascript compresser someone recommended).
- This is unnecessary. Just delete line breaks in the original code until it fits.

- You should really get in the practice of always having some Wait command in parallel events. How much you wait depends on how precise you need any of the timing to be, but none of the things you have here need to be checked 60 times a second. Give them all a Wait of, like, 10 frames. That's how you start creating lag in your game.

-- Especially for things like page 2 - why is that a parallel event at all? It does nothing, but you're making the engine reference it 60 times a second. Just leave the trigger as Action Button.

- I don't see the point of giving your first page the condition of self switch A being off. You can't get lower than event page 3 unless self switch A is already off, so there's no reason to check it.

To speak to your actual problem:
if I spawn new seeds/plants after one plant dies, it will spawn as a dead plant.
That sounds to me like the spawned event IDs are being recycled. That is, your newly planted seeds are referencing the event ID of one that was previously spawned then deleted, so the self variable values are the same.

If I'm correct, all you need to do is reinitialize all of your self variables before you delete the dead plant event.

If you're not deleting them and my hypothesis isn't applicable...please post your Bed common event script in regular syntax. That line is illegible, and speaking for myself I'm not going to go through it adding line breaks just so I can read it 😛
A few things:

- It would be very useful to note that you appear to be using HimeWorks' Custom Page Conditions and link to that plugin. I'm presuming that from Googling.


- This is unnecessary. Just delete line breaks in the original code until it fits.

- You should really get in the practice of always having some Wait command in parallel events. How much you wait depends on how precise you need any of the timing to be, but none of the things you have here need to be checked 60 times a second. Give them all a Wait of, like, 10 frames. That's how you start creating lag in your game.

-- Especially for things like page 2 - why is that a parallel event at all? It does nothing, but you're making the engine reference it 60 times a second. Just leave the trigger as Action Button.

- I don't see the point of giving your first page the condition of self switch A being off. You can't get lower than event page 3 unless self switch A is already off, so there's no reason to check it.

To speak to your actual problem:

That sounds to me like the spawned event IDs are being recycled. That is, your newly planted seeds are referencing the event ID of one that was previously spawned then deleted, so the self variable values are the same.

If I'm correct, all you need to do is reinitialize all of your self variables before you delete the dead plant event.

If you're not deleting them and my hypothesis isn't applicable...please post your Bed common event script in regular syntax. That line is illegible, and speaking for myself I'm not going to go through it adding line breaks just so I can read it 😛
Many apologies, a lot of what I've done is theory crafting and mainly just me doing sloppy coding in order to get the general basis, and then cleaning it up for mass reproduction. Also, you are correct in that I am using Himeworks Custom Page conditions! I forgot to mention it at all since I was so focused on fixing the spawn issue.


Code:
mapId = $gameVariables.value(18);var eventId = $gameVariables.value(19);var varId = 26;var deathId = 30;var harvestId = 31;
var value = this.getSelfVariableValue(mapId, eventId, varId);var death = this.getSelfVariableValue(mapId, eventId, deathId);var harvest = this.getSelfVariableValue(mapId, eventId, harvestId);
if (value <= 0) death -= 1;
if (value > 0) value -= 1;
if (value > 0) harvest -= 1;
this.setSelfVariableValue(mapId, eventId, varId, value);
this.setSelfVariableValue(mapId, eventId, deathId, death);
this.setSelfVariableValue(mapId, eventId, harvestId, harvest);

Here is the script! I was unaware that it could be pressed together like this, so I simply followed the compress method I saw some other forum listed!

I planned on adding waits in the future, but I was just trying to get the basis of how the code will work, and if I can get it to the point of making a variety of plants.

Screen Shot 2023-05-03 at 3.30.31 PM.png

This is the plant respawn common event in full. It checks IDs 1 through 1999 as Yanfly's event Ids seem to start at 1000, and if I start it at 1000 it doesn't properly update things.

Screen Shot 2023-05-03 at 3.30.34 PM.png

This is the update where you select a map Id and then run the respawn Cycler

Screen Shot 2023-05-03 at 3.30.37 PM.png


And this is the bed event. It just uses the update respawn cycler with the map Id.

This all seems to run fine, but the issue lies in getting a plant to spawn as a live one, and a dead one to remain dead. I don't know if I need a secondary self variable that kills the plant versus one, or if there's something else entirely that I'm missing. I'm at a beginner's level in javascript, but I'm quick to learn things. My fatal flaw is that I'm probably missing something so simple lol.

Thank you again in advance!!
At the beginning of the script, you should declare mapId using var or let, like the other variables, so you're not creating a global variable.

Code:
var varId = 26;
var deathId = 30;
var harvestId = 31;
var value = this.getSelfVariableValue(mapId, eventId, varId);
var death = this.getSelfVariableValue(mapId, eventId, deathId);
var harvest = this.getSelfVariableValue(mapId, eventId, harvestId);
It's not making the code malfunction, but I suggest all this is making matters harder to read with the extra variables rather than easier. Why not just:
Code:
var value = this.getSelfVariableValue(mapId, eventId, 26);
var death = this.getSelfVariableValue(mapId, eventId, 30);
var harvest = this.getSelfVariableValue(mapId, eventId, 31);
That way, someone else reading your code (or you reading it later) doesn't need to look back and forth just to see what values are being referenced.

I don't see where self variable 26 is referenced anyplace in your events above, so I don't know whether the rest of your logic is correct. Is that "watered"? The name "value" doesn't tell me what it's for.
This is the plant respawn common event in full. It checks IDs 1 through 1999 as Yanfly's event Ids seem to start at 1000, and if I start it at 1000 it doesn't properly update things.
That's definitely a clue something is off. If you set the spawning IDs to start at 1000 and something doesn't update when you actually go from 1000, you need to do some troubleshooting to figure out what the ID is of the event that's not updating.

Right now you're making the game do a lot of stuff it doesn't need to do, and possibly affecting events you don't want to affect (for example, if you're spawning from a template event on this map, that's why everything is borked because you're changing the values on the event that's being copied).

On any of the event pages you can put a Script call for console.log("Event ID is ", this.eventId())

Then you press F12, go to the Console tab, and see what values they're reporting.
At the beginning of the script, you should declare mapId using var or let, like the other variables, so you're not creating a global variable.

Code:
var varId = 26;
var deathId = 30;
var harvestId = 31;
var value = this.getSelfVariableValue(mapId, eventId, varId);
var death = this.getSelfVariableValue(mapId, eventId, deathId);
var harvest = this.getSelfVariableValue(mapId, eventId, harvestId);
It's not making the code malfunction, but I suggest all this is making matters harder to read with the extra variables rather than easier. Why not just:
Code:
var value = this.getSelfVariableValue(mapId, eventId, 26);
var death = this.getSelfVariableValue(mapId, eventId, 30);
var harvest = this.getSelfVariableValue(mapId, eventId, 31);
That way, someone else reading your code (or you reading it later) doesn't need to look back and forth just to see what values are being referenced.

I don't see where self variable 26 is referenced anyplace in your events above, so I don't know whether the rest of your logic is correct. Is that "watered"? The name "value" doesn't tell me what it's for.

That's definitely a clue something is off. If you set the spawning IDs to start at 1000 and something doesn't update when you actually go from 1000, you need to do some troubleshooting to figure out what the ID is of the event that's not updating.

Right now you're making the game do a lot of stuff it doesn't need to do, and possibly affecting events you don't want to affect (for example, if you're spawning from a template event on this map, that's why everything is borked because you're changing the values on the event that's being copied).

On any of the event pages you can put a Script call for console.log("Event ID is ", this.eventId())

Then you press F12, go to the Console tab, and see what values they're reporting.
Okay so I played with things, and now the engine is allowing me to start from 1000 (I swear this thing just hates me sometimes), so that doesn't seem to be the issue. Also, it has to be so blocky with the variables separated from the this.selfvariablevalue is something to do with yanfly's self variable code it appears as it no longer registers as me referencing a self variable. So even though it is blocky, I can hopefully just explain in the future. Also yes, varId and value are my "watered" variable/variable 26. I was using the eventing a foraging code as a base to build off of, so I had just changed the integers before adding additional code to them.

I have reran the events to see if it was fixed at all, so the variables are still being read as changed when new events are spawned. It shouldn't affect my spawned events as the map that the variables are being updated on is on map 4, and the event cycler will only run on map 1. My only theory is that I need to somehow reset the variable once it hits a certain point. If i have the variable recycler update it, then the plants will only come back to life after death, or they will never reach a death state at all. When I try and put it into an event page, another one blocks it for one reason or another. I want a perma death state until the player removes the dead plant from the plot, so I figured that having a parallel event with a self switch may have been an answer, and I moved the different event pages around, but event priorities seem to always bork whatever I'm trying to do.

I feel like I'm super close to the answer, but I just can't seem to get there, or I take like two steps back from what I'm trying to do :/
If i have the variable recycler update it, then the plants will only come back to life after death, or they will never reach a death state at all.
When your player removes the dead plant, put a command to set the self switch of the dead plant back to the beginning page (or just uncheck/set false the self switch of whatever page it's currently on). Then a command to unspawn the event.
When your player removes the dead plant, put a command to set the self switch of the dead plant back to the beginning page (or just uncheck/set false the self switch of whatever page it's currently on). Then a command to unspawn the event.
I’m at work so sorry for the late reply! But the despawning of the plant when it’s dead via player input isn’t the problem. My issue is I put a plant down. Three days pass, and it dies. If I try to place a new plant while the dead plant remains, the new plant will spawn as a dead plant and not as a seed. Do you get what I mean?

If not, I can record a screen video and post it when I get home!
I’m at work so sorry for the late reply! But the despawning of the plant when it’s dead via player input isn’t the problem. My issue is I put a plant down. Three days pass, and it dies. If I try to place a new plant while the dead plant remains, the new plant will spawn as a dead plant and not as a seed. Do you get what I mean?

If not, I can record a screen video and post it when I get home!
I'm saying you should reset the dead plant to the beginning page right before you despawn it. The eventId is getting reused by the new spawn.
I'm saying you should reset the dead plant to the beginning page right before you despawn it. The eventId is getting reused by the new spawn.
How is it reusing the ID if the plant is never despawned in the first place? It shouldn’t be reusing any if the dead plant is still there, right? I’m saying if I keep the dead plant, it’s affecting brand new spawns while the original dead plant is there
How is it reusing the ID if the plant is never despawned in the first place? It shouldn’t be reusing any if the dead plant is still there, right? I’m saying if I keep the dead plant, it’s affecting brand new spawns while the original dead plant is there
Then one of your variables is being shared across multiple plants instead of being contained to a self variable.
Also, it has to be so blocky with the variables separated from the this.selfvariablevalue is something to do with yanfly's self variable code it appears as it no longer registers as me referencing a self variable.
I'm not exactly certain what you're saying here, but it just isn't the case.
Code:
var varId = 26;
var value = this.getSelfVariableValue(mapId, eventId, varId);
and
Code:
var value = this.getSelfVariableValue(mapId, eventId, 26);
will produce exactly the same result in JavaScript. There is no way to code the plugin such that it doesn't.

This isn't a huge deal, just like I said, it makes it more immediately readable (and it's fewer lines you have to combine to make it fit into a Script box).

I'm trying to read through the various events you posted to see if I can see an error, but it's just very difficult because you have so many things and it's split up so much. Like, what's the point of the Update Plant Water Respawn? All it does is set one variable to a specific value then immediately call another common event. You could get rid of that and just call the Plant Water Respawn directly, and set that variable equal to 1 there. Or skip the variable and use the value 1 in your code.

The other thing that looks weird to me is page 3 of your plants. You still haven't shown what your Water Plant event looks like, but it looks weird that you have spawned events which are individual things; you're using self variables on those events, which are individual things; but then you're calling a common event that's going to have some general effect on everything.

And all of your plants are calling that common event, potentially many times a second. It just seems like that should not be something that's contained within the plant events. There's a high potential there to be affecting your events or variables in a way that you don't intend.

Ultimately, with the problem you're having, I see only two viable causes:
1 - with the convolution and many components of your system, you're making a mistake someplace and setting the water self variable on the origin event or setting it outside of an event such that it overwrites the value for everything.

2 - have you double checked the installation of your Yanfly plugins? Specifically, the order must match what's on the Yanfly Engine Web site, or random glitches can occur.

I don't know that there's much more we can do to try to remotely troubleshoot for you, unless you're willing to share a download of your project with instructions on how to duplicate the bug. If you do that, do not distribute any Yanfly plugins with it.
You might want to get Super Tools for your game testing. It lets you see the value of all your Control Variables and Switches while playtesting and you can manually change the values to see how that effects your plants.
Screenshot 2023-05-03 193247.png
Then one of your variables is being shared across multiple plants instead of being contained to a self variable.
That's the thing. If I create Plant A and Plant B, and Plant A dies, then Plant B will continue to act as its own plant. It's only when plant C, D, etc. are created that the issue occurs.



I'm not exactly certain what you're saying here, but it just isn't the case.
Code:
var varId = 26;
var value = this.getSelfVariableValue(mapId, eventId, varId);
and
Code:
var value = this.getSelfVariableValue(mapId, eventId, 26);
will produce exactly the same result in JavaScript. There is no way to code the plugin such that it doesn't.

This isn't a huge deal, just like I said, it makes it more immediately readable (and it's fewer lines you have to combine to make it fit into a Script box).

I'm trying to read through the various events you posted to see if I can see an error, but it's just very difficult because you have so many things and it's split up so much. Like, what's the point of the Update Plant Water Respawn? All it does is set one variable to a specific value then immediately call another common event. You could get rid of that and just call the Plant Water Respawn directly, and set that variable equal to 1 there. Or skip the variable and use the value 1 in your code.

The other thing that looks weird to me is page 3 of your plants. You still haven't shown what your Water Plant event looks like, but it looks weird that you have spawned events which are individual things; you're using self variables on those events, which are individual things; but then you're calling a common event that's going to have some general effect on everything.

And all of your plants are calling that common event, potentially many times a second. It just seems like that should not be something that's contained within the plant events. There's a high potential there to be affecting your events or variables in a way that you don't intend.

Ultimately, with the problem you're having, I see only two viable causes:
1 - with the convolution and many components of your system, you're making a mistake someplace and setting the water self variable on the origin event or setting it outside of an event such that it overwrites the value for everything.

2 - have you double checked the installation of your Yanfly plugins? Specifically, the order must match what's on the Yanfly Engine Web site, or random glitches can occur.

I don't know that there's much more we can do to try to remotely troubleshoot for you, unless you're willing to share a download of your project with instructions on how to duplicate the bug. If you do that, do not distribute any Yanfly plugins with it.
What I am saying is that when I put it copy and pasted as you did, it no longer responded and updated the self variables.

Additionally, here is my water common event.

Screen Shot 2023-05-03 at 10.32.49 PM.png
Screen Shot 2023-05-03 at 10.32.53 PM.png


All this does is affect the self variable of being watered or not and check which event is being affected. I do not see it having an issue with the death, save for in the plant update. And I do the self variable update like how Yanfly does it, as it seems to work for reharvestable berries, so why wouldn't it work for factors such as death, harvest, and water? If i need to somehow make this more "convoluted" as you say and separate the death variable from the harvest and water variables, I'm more than happy to do so. I just really didn't want to use Galv's crops plugin as I wanted my game to have unique factors such as a farming system that allows for animated crops versus Galv's which keeps it stagnant.

If there's really no hope, and I'm being told to just drop it, I will cut out the death aspect from the crops altogether, but I really wanted this to be a part of the crop sequence as it keeps the player drawn in and allows them to take part in managing the crops.
You might want to get Super Tools for your game testing. It lets you see the value of all your Control Variables and Switches while playtesting and you can manually change the values to see how that effects your plants.
View attachment 260847
So using the super tools, the variable just gives me 0 for all of my self variables, so I don't think it's going to help unfortunately. I appreciate the offer though!
See, right there, you're trying to use self variables in a common event.

You can't do that, because
1 - common events don't have self variables, only map events do.

2 - at the bottom, where you're trying to change the watered self variable, that has nothing to do with any plant.

If it did affect a self variable, it would be on the common event - it has no way of knowing what map event called this common event to affect its self variables.

If i need to somehow make this more "convoluted" as you say...
I don't know where you got that from, I said the exact opposite. I said it's so convoluted and split into different components that it's greatly increasing the difficulty of reading it and the chance of error - like in the above. By putting that into a common event it no longer does what you want it to.

If there's really no hope, and I'm being told to just drop it...
Again, that is not at all reflective of the words I said to you.

But I think further help needs to either let people look at your actual project or ask for help rewriting this system, because trying to go back and forth and look at all of these screen shots scattered across a thread is just too difficult to deal with.

@AquaEcho I haven't used it, but I wouldn't expect the Super Tools would work correctly with this plugin. It turns the self variables into arrays, and the screenshot you show doesn't look like the Tools are able to display that. Printing the variable to the console from inside the event would produce better results.
If there's really no hope, and I'm being told to just drop it, I will cut out the death aspect from the crops altogether, but I really wanted this to be a part of the crop sequence as it keeps the player drawn in and allows them to take part in managing the crops.
No one told you to give up. We're both giving our time for free to help you solve this and your dedication to crafting the system to just how you want it is admirable.

@AquaEcho I haven't used it, but I wouldn't expect the Super Tools would work correctly with this plugin. It turns the self variables into arrays, and the screenshot you show doesn't look like the Tools are able to display that. Printing the variable to the console from inside the event would produce better results.
The reason I recommended Super Tools is because I think the issue is one of the control variables and it lets you see the value of the control variables and lets you change them on the fly.
See, right there, you're trying to use self variables in a common event.

You can't do that, because
1 - common events don't have self variables, only map events do.

2 - at the bottom, where you're trying to change the watered self variable, that has nothing to do with any plant.

If it did affect a self variable, it would be on the common event - it has no way of knowing what map event called this common event to affect its self variables.


I don't know where you got that from, I said the exact opposite. I said it's so convoluted and split into different components that it's greatly increasing the difficulty of reading it and the chance of error - like in the above. By putting that into a common event it no longer does what you want it to.


Again, that is not at all reflective of the words I said to you.

But I think further help needs to either let people look at your actual project or ask for help rewriting this system, because trying to go back and forth and look at all of these screen shots scattered across a thread is just too difficult to deal with.
That wasn't directed at you, I keep getting told to drop the idea and just use Galv by others in a different location, sorry. I'm just super frustrated, and I'm open to trying to rewrite the system. The water common event hasn't effected anything as far as I am aware. It only adds the water variable to the event in the player's x, y. The only issue I am having is the fact that the plants are not updating the death variable correctly.

I get that I am a beginner, but I feel like I am being scolded for trying to theory craft and make things work. The common event is used as a parallel process, and it is run only when the player uses the ok button while a watering can is equipped.

Nothing else in my system is broken, except where the death variable is involved.
No one told you to give up. We're both giving our time for free to help you solve this and your dedication to crafting the system to just how you want it is admirable.


The reason I recommended Super Tools is because I think the issue is one of the control variables and it lets you see the value of the control variables and lets you change them on the fly.
Again, it's not you, I'm just frustrated at hell cause other options for help have led to snobby "I'm better at programming than you" people giving me a defeatist attitude towards everything. I apologize for getting upset, it's just something I've wanted to do for 2+ years, and now that it's so close, it's just sucks.
And yet you've also said in a few places that syntactically valid JavaScript isn't working in your project. This tells me that something is wrong, whether you see evidence of it or not.

To be fair, I just looked into the common event thing and Yanfly did specifically add code that stores which map event is calling a common event, so self variables/switches used in it will correctly refer back to the original map event. That's pretty neat, and I didn't know it did that.

Aside from that...I don't know what to say beyond what I already have.
I did recommend Galv's system as an out-of-the-box solution but since you were willing to put in the work for a custom solution I was willing to help you get it done. If you PM me about any issue you have I'll give you the best answer I can.

"I'm better at programming than you"
Don't let that get you down. We have regular posters here who cannot read or write code but are making steady progress on their games, and programming is just one aspect of game dev. People won't even download a game if they don't like how it looks, no matter how optimally programmed it is. I've also seen people raving about games that were full of bugs and randomly crashed.

Original thread: https://forums.rpgmakerweb.com/threads/event-page-order-help.157193/