Odd bug when manipulating variables via common event

So I'm using a common event to manipulate some variables. This common event is called by an item, so it's not like it's supposed to be running all the time and something's getting jammed up there.

Now, what seems to be happening is that every time I want this common event to manipulate a variable and then NOT DO ANYTHING ELSE, it has a conniption fit and manipulates the variable A WHOLE BUNCH OF TIMES, causing insane lag and a crapload of logic errors.

I have a simple If/Else statement. If it evaluates to True, I want the event to set a certain variable to 100. If it evaluates False, I want the event to subtract 10 from the variable's value. (And yes, I am making sure the variable is already set to Something More Than 0 before this common event is able to be called.)

That's it. I want the event to end as soon as the variable is changed one way or the other. I do not want to display any text about it, etc.

Now, like I said, the engine does not seem to like this. When I use the item and call the common event under conditions that make my If/Else evaluate true, there's about a second and a half freeze, and then the variable is set correctly. But when I call the event under conditions that should make the If/Else evaluate FALSE, there's the same lag, and the variable is set to something like -90,0640 (I am not exaggerating. Interestingly, the value the variable gets set to is not always the same, though it's always somewhere around -90,000). Which tells me that instead of simply setting the variable ONCE, it is doing it an ungodly number of times.

I have no idea WHY this is happening, or how to stop it. The operation works fine if I copy and paste the code into an event on the map. The problem is only happening with the common event called by the item. It happens with zero plugins active, and it happens with the full VisuStella suite + Community Lighting and a few other things. It happens in a BRAND NEW PROJECT. (And yes, I am running the latest version of everything.)

IT DOES NOT HAPPEN, HOWEVER, IF I TELL THE GAME TO DISPLAY A TEXT BOX AFTER MANIPULATING THE VARIABLE

It DOES still happen if I tell it to play a sound effect, or to Exit Event Processing, or to Break Loop (a longshot, I know, but I thought it was worth a try).

Does anybody know wtf is going on here?? Is it a bug in the engine? Am I doing?? something??? wrong? I feel like I've seen or heard of something similar to this happening before, but Google and my memory are both failing me.
I've seen similar problems in previous versions of Rpg Maker, but they were due to lack of gap, like a "Sleep/Wait" at the beginning or end, as events in parallel process are usually already looping.

Example:
Code:
◆Command X
◆Wait:10 frames
I've seen similar problems in previous versions of Rpg Maker, but they were due to lack of gap, like a "Sleep/Wait" at the beginning or end, as events in parallel process are usually already looping.

Example:
Code:
◆Command X
◆Wait:10 frames

BEAUTIFUL. Adding a ten frame wait command fixes the problem entirely.
I have no idea why we need a wait command in a common event but not a map event, but I DO NOT CARE.

Thank you so much for helping me!
This comes from Rm2k, the default looping of EVENTS is very fast and it over loads performance, regardless of whether it is in the map or common.

See this flashlight system using Pictures:
Spoiler: Youtube + Tutorial + Download
Youtube
(And it's a very simple system, sorry for the topic of the links, I made the tutorial in my first language)

Without the wait, making the image follow the player, giving a little wait can greatly affect the end-customers gameplay depending on the computer.
This sounds very odd - I'd love to see a screenshot of your common event (the whole thing, not just the event commands), and to know what plugins you have.

A common event that is called by an item should not loop at all.
what is the trigger of your common event?

if an event is called, then it HAS TO BE set to "None" as a trigger.
If you make the mistake to set it to parallel but then call it instead of using a switch trigger, then the engine quirks and may cause unintended results.
A common event that is called by an item should not loop at all.
I assumed he used the Event Loop command when I read this:
It DOES still happen if I tell it to play a sound effect, or to Exit Event Processing, or to Break Loop (a longshot, I know, but I thought it was worth a try).

Example:
Code:
◆Loop
  ◆Control Variables:#0001 CountTime += 1
  ◆If:CountTime ≥ 100
    ◆Break Loop
    ◆
  :End
  ◆Wait:10 frames
  ◆
:Repeat Above
◆Comment:End Event-Item
I assumed he used the Event Loop command
I assumed he was just guessing at anything that might have stopped processing, and may not have even had any loops.

That's the trouble with people trying to explain what they did rather than actually showing - an explanation is way open to interpretation.
what is the trigger of your common event?

if an event is called, then it HAS TO BE set to "None" as a trigger.
If you make the mistake to set it to parallel but then call it instead of using a switch trigger, then the engine quirks and may cause unintended results.

I assumed he used the Event Loop command when I read this:


Example:
Code:
◆Loop
  ◆Control Variables:#0001 CountTime += 1
  ◆If:CountTime ≥ 100
    ◆Break Loop
    ◆
  :End
  ◆Wait:10 frames
  ◆
:Repeat Above
◆Comment:End Event-Item

Seems there's been some confusion! I am NOT using a loop at all in this Common Event - I just tried the "break loop" command in desperation, because it seemed to me like SOMETHING was looping when it definitely shouldn't be.

Attached is a screenshot of the part of the Common Event code that was malfunctioning. (I'm working on a plant-growing system.) Please excuse the excessive commenting - I'm basically writing everything I want to do out in "psuedo-code" comments and then figuring the actual event commands or script calls. (It probably looks ridiculous, but it's been a great help in keeping my train of thought from getting too tangled up as I'm learning.)


EDIT: Next time, I should probably remember to include a screenshot with my initial question. Sorry for the confusion, everyone!
I'd love to see a screenshot of your common event (the whole thing, not just the event commands), and to know what plugins you have.
See the bit in bold there? There is a reason I said that.

What is the trigger on the common event? Do you have anything that jumps to that label?

Pseudocode is awesome - if more people used it, there'd be fewer people asking for help because their events aren't working.
See the bit in bold there? There is a reason I said that.

What is the trigger on the common event? Do you have anything that jumps to that label?

Pseudocode is awesome - if more people used it, there'd be fewer people asking for help because their events aren't working.
Ah, sorry. I guess I got flustered, and my reading comprehension fell off. ^^;

I do have something that jumps to the label, but actually, the labels weren't inserted until I was trying to troubleshoot the lag problem. The trigger for the event is set to "None" and the event is only called when a Key Item is used from the menu.

I'm attaching four screenshots that should show the ENTIRE code of the common event as it stands now. There's some stuff I've marked off with a red box - that wasn't in the event when I first posted this topic. I only added it AFTER solving the "wait 10 frames" issue.


EDIT: Thanks very much for helping troubleshoot this, btw. My plugin list for this project has gotten a bit hefty (amazing how quickly things add up, isn't it?), but I was able to replicate this issue in a completely fresh project (I used a separate, on-map event to display a text box with the variables via escape code so I'd know what they were getting set to, in the absence of a native debug screen) with absolutely no plugins added at all. So. It's definitely something happening in the main engine, and not a matter of plugin incompatibility etc.
Could you zip up the data file of that new project and send it to me please? I'd love to take a good look at it! And of course tell me what steps I need to take to make the issue happen.
Could you zip up the data file of that new project and send it to me please? I'd love to take a good look at it! And of course tell me what steps I need to take to make the issue happen.
I've left the house for the evening (I work nights), but I'll try to remember to send it to you as soon as I get home. If not, I'll get it done first thing tomorrow. 🙂
Okay, so I got your test project, and I'm sorry to say that it works perfectly for me. I go to the water and fill the bucket to 100, then I tip some out, and each time I do, it reduces the amount of water by 10. I got it to 90, 80, 70, 60 and figured I'd stop there.

Are you actually saying that, with the project you sent me, you are having this issue? Can you try again and just confirm that?

The only thing I wonder about is where you're setting variable 22, and what value you're putting into it. For me, it's 0, because you're not setting/changing it anywhere. But for you, it could be some ridiculously low number and that would cause the issue you're seeing. Or you might have something else changing your variables. Try doing an event search, but be aware that this will not pick up where you've used or changed a variable in a script command, or plugins.

If that doesn't help and you still can't figure it out, I'm happy for you to send me your real project - as long as you make it just as easy to get the bucket and test the common event.
Okay, so I got your test project, and I'm sorry to say that it works perfectly for me. I go to the water and fill the bucket to 100, then I tip some out, and each time I do, it reduces the amount of water by 10. I got it to 90, 80, 70, 60 and figured I'd stop there.

Are you actually saying that, with the project you sent me, you are having this issue? Can you try again and just confirm that?

The only thing I wonder about is where you're setting variable 22, and what value you're putting into it. For me, it's 0, because you're not setting/changing it anywhere. But for you, it could be some ridiculously low number and that would cause the issue you're seeing. Or you might have something else changing your variables. Try doing an event search, but be aware that this will not pick up where you've used or changed a variable in a script command, or plugins.

If that doesn't help and you still can't figure it out, I'm happy for you to send me your real project - as long as you make it just as easy to get the bucket and test the common event.

Hmm. That's...Bizarre. Because I am getting the bug reliably in the exact test project I zipped up and sent to you. I tested it quite a bit right before I sent it to you, and I've just now downloaded it and tested it again, and on my machine the bug still happens.

In that test project, unless/until you use the bucket, the variable doesn't get set, and is therefore zero. However, if I first use the bucket on the water, it gets set to 100. Then, I can use the bucket on Not Water and it gets set to an absurdly low number. Not using the bucket on water (and therefore setting the variable to 100 instead of 0) first before trying the Not Water option doesn't seem to change anything for me. The variable starts at 0, and then upon using the bucket on Not Water it goes absurdly low again.

I'm running RPG Maker MZ version 1.3.2 on Windows 10 Pro edition. I don't think my Java version should matter here, but just in case, it's Version 8 Update 271.
It doesn't really matter which version of the engine you're running - it's the version of the scripts, and I am running exactly what you gave me.

Are you going into debug at each step and seeing what those variables are set to?




I will mention, I also don't see the lag you talk about at any point in the game.
@GammaVector when you test, are you starting a new game each time, or are you loading a saved file when testing the event?

because a savefile can contain an old version of map data or plugin data or a few other things that can cause problems, and if your bug is in the savefile it would explain why @Shaz is not getting it.
It doesn't really matter which version of the engine you're running - it's the version of the scripts, and I am running exactly what you gave me.

Are you going into debug at each step and seeing what those variables are set to?




I will mention, I also don't see the lag you talk about at any point in the game.

Well, I didn't actually know how to get into debug before now...But yes, I've now verified it with debug, and NOT just the text box escape code.


@GammaVector when you test, are you starting a new game each time, or are you loading a saved file when testing the event?

because a savefile can contain an old version of map data or plugin data or a few other things that can cause problems, and if your bug is in the savefile it would explain why @Shaz is not getting it.

Nope! No save files whatsoever. New game every time.

It appears to be just...specific to my machine. Which is bizarre. But Shaz isn't getting it, and a few minutes ago I ran the following test:

1: Download zipped file using same link I sent to Shaz.
2: Unzip project and run it on my computer.
3: Bug happening reliably.
4: Download project onto WIFE'S computer, try running it there.
5: BUG NO LONGER HAPPENS. CANNOT GET IT TO OCCUR EVEN ONCE

I got nothing. I have absolutely no idea what is happening with my specific computer that is causing this bug to occur. I have no idea why adding a 10 frame wait command directly after manipulating the variable fixes it. I'm?????????

I'm so sorry for all this trouble. ^^;
I can't imagine it's ONLY my machine that would ever act like this, but I don't even know where to start with trying to figure out why it's acting differently on my specific computer. It's probably not worth the effort to pursue, but if anyone has any ideas or more questions to ask...I'm all ears.
there is always a reason for any reproducable problem, but it can be difficult to find and as you said, it is not always worth the time.

The worst case of wtf that I personally encountered (and solved more by accident than anything else) in computer support was a series of computers where installing a wrong mouse driver on Win98 resulted in a display glitch on going down to DOS after the driver was active. Somehow that wrong driver must have disrupted the memory allocation to the display driver for the DOS display (it didn't happen when you booted to DOS directly, only after that driver was loaded). And my company had sold about 100K computers where the two mouse drivers (the correct one and the wrong one) where in the same folder for customer convenience on reinstalling...

It is probably something similar - some driver accessing the wrong memory segments on your computer or something like that. Almost impossible to find without a lot of searching.

Original thread: https://forums.rpgmakerweb.com/threads/odd-bug-when-manipulating-variables-via-common-event.138548/