Bug? when using loop right after assigning common Event to variable

So my code looks something like this.

Control Variables: #0001 Eventcaller = $gameTemp.reserveCommonEvent($gameVariables.value(1));
Loop

repeat above

Somehow that doesnt work and i dont understand why. Can someone explain?
I saw your other thread about this too, and I think there's some confusion here.

You asked people to tell you how to store a common event in a variable. They gave you the command to call a common event as a script call, but you said you didn't need to call it right away, and instead wanted to store it for later, so they suggested you store the common event ID in a variable when you wanted to 'reserve' it, and then call the actual command later.

What you appear to have done here instead, was saved a string into a variable, and that string contains the value of the variable you're saving it into, so every turn of the loop will increase what's in the variable, infinitely, until it causes an overflow and dies. Since you have no wait in your loop, that probably happens within a second of starting the event.

What exactly are you trying to do with this? The suggestion was to store the common event ID in the variable, and then use the script to call it later when you needed it. In two steps. The step that would reserve the common event would set the ID in the variable, the event that needs to call the common event would do so using the script call you have right there.

What you're doing is storing a recursive string into a variable, and then looping it so it constantly overwrites itself.
What you're doing is storing a recursive string into a variable, and then looping it so it constantly overwrites itself.

Not even... The loop is empty. The loop starts AGTER the control Variable, so it sets the var once, and then start an endless loop of doing nothing.

This will basically freeze the game.

@OP, your loop can never be empty. Even when there are commands in your loop, you need to set away to break that loop. (Like, at the end of the loop, you take away 1 from another variable, and when it hits 0, you break the loop, for example)
(Also, technically $gameTemp.reserveCommonEvent returns undefined, not a string. Since that's a falsy value, $gameVariables.value will return 0.)

In summary, I think you'll want two separate events:
  1. Store event ID in a variable (Control Variables), e.g.

    ◆Control Variables:#0001 = 123
  2. Reserve that common event (Script), e.g.

    ◆Script:$gameTemp.reserveCommonEvent($gameVariables.value(1));
I'm not sure why you tried to put a loop in there, though. Are you trying to trigger this on a timer or something?
1687965511397.png

Soo this is what causes the bug. I dont know why, but this doesnt call the event.

This however does work
1687965579739.png

But it only calls the event, when the loop is finished, which is not what i want.

What im trying to do is build my own fight system and for that i use multiple common events.
I use 3 Unique common events that controll the current fight and then i have other common events that have shared code.

In one of my unique events there is a loop with attack choices and i want to give my common event information about which events it should call.
View attachment 267245
Soo this is what causes the bug. I dont know why, but this doesnt call the event.

This however does work
View attachment 267246
But it only calls the event, when the loop is finished, which is not what i want.

What im trying to do is build my own fight system and for that i use multiple common events.
I use 3 Unique common events that controll the current fight and then i have other common events that have shared code.

In one of my unique events there is a loop with attack choices and i want to give my common event information about which events it should call.

???? The loop still does nothing there... Why is that loop there? This really doesn't do anything. If there is nothing that should be repeated, then you don't need a loop.

---

Do it like this:
1687968036159.png


The upper command sets the ID, the next command calls for the common event with that ID.
???? The loop still does nothing there... Why is that loop there? This really doesn't do anything. If there is nothing that should be repeated, then you don't need a loop.

---

Do it like this:
View attachment 267248

The upper command sets the ID, the next command calls for the common event with that ID.
The second code is just an example. I have lots of stuff inside the loop.

I'll try your suggestion out now
Also, the common event only runs after the current event is finished because that's how "reserve" common event works. Here are a couple of options:
  • Reserve common event 2 (runs at the next opportunity):
    JavaScript:
    $gameTemp.reserveCommonEvent($gameVariables.value(2));
  • Call common event 2 (embeds common event commands into the current event):
    JavaScript:
    this.command117([$gameVariables.value(2)]);
As seen in John's screenshot, these are for use in a standalone Script command. You would only need to use Control Variables if you wanted to store the result, but reserving/calling an event does not return a useful result.

(@JohnDoeNews - typo in your screenshot: your script call starts with ◆Script:, which would cause an error.)
@IareaGuys
If the comments above do not help you, then you need to take a step back and explain to us the entire structure of your battlesystem before we can give better help.

Because at the moment your descriptions are completely disjuncted and make you sound as if you try to construct an advanced event system while missing basic eventing knowledge, like some 10-year-old schoolchild trying to construct a real car with a combustion engine when first stepping into a garage shop.
(@JohnDoeNews - typo in your screenshot: your script call starts with ◆Script:, which would cause an error.)

Oops. I copy/pasted from your post... I copied too much.
@IareaGuys
If the comments above do not help you, then you need to take a step back and explain to us the entire structure of your battlesystem before we can give better help.

Because at the moment your descriptions are completely disjuncted and make you sound as if you try to construct an advanced event system while missing basic eventing knowledge, like some 10-year-old schoolchild trying to construct a real car with a combustion engine when first stepping into a garage shop.
Well i dont show the actual code, as there would simply be too much stuff going on, which has nothing to do with the problem. I try to isolate, where the problem lies by trial and error, so there is no unnecessary code.

Also it works now with this:
Also, the common event only runs after the current event is finished because that's how "reserve" common event works. Here are a couple of options:
  • Reserve common event 2 (runs at the next opportunity):
    JavaScript:
    $gameTemp.reserveCommonEvent($gameVariables.value(2));
  • Call common event 2 (embeds common event commands into the current event):
    JavaScript:
    this.command117([$gameVariables.value(2)]);
As seen in John's screenshot, these are for use in a standalone Script command. You would only need to use Control Variables if you wanted to store the result, but reserving/calling an event does not return a useful result.

(@JohnDoeNews - typo in your screenshot: your script call starts with ◆Script:, which would cause an error.)

Thanks for your help
Well i dont show the actual code, as there would simply be too much stuff going on, which has nothing to do with the problem. I try to isolate, where the problem lies by trial and error, so there is no unnecessary code.

Accept for the loop. That being there was confusing because the rest was removed. 😛

If you want to leave out unnessecary parts, it's easier to crop.

Anyhow, happy it works?

Original thread: https://forums.rpgmakerweb.com/threads/bug-when-using-loop-right-after-assigning-common-event-to-variable.158754/