Is there a timing issue with Loops?

Is there a timing issue I don't know about?
I've created a Loop, and when it runs, it seems to skip over a lot of the variable inputs and just displays them as "0".

However, if I add a 1 frame Wait command at the bottom before it repeats, it displays what I need with a minor 10th of a second delay.

If I break down the loop and manually put the conditions in, it also displays just fine, but with no delay. But it's a LONG event that I have to repeat many times. I'm trying to simplify things to make them easy to duplicate.

I split up the Script Calls that were originally in 1 Script Call box hoping that would do the trick. It did not.

The event goes through the Loop 8 times before a Break Loop condition happens. So, we're talking about an 8 frame delay. About a minor 13% of a second. It's not horrible, but not seamless either.

Can anyone shed some light on what's going on?

RPG Timing.png
not exactly - what you see here is the difference between parallel process and evented loop in the main game loop

by default the parallel process allows the game loop to continue between its own iteration.
the event loop however does not (not on its own at least).
However if a command inside the event loop requires the regular game loop to process, then it does so. And wait is a command that actualy tells the main game loop "skip processing this event for x loops/frames", which allows the rest of the game elements to process.

The problem here is that if nothing allows the game loop to process, then nothing else will happen - which is why an event loop comand is one of the few things that can freeze the entire game.

I hven't checked your event in detail, but I assume the scripts and other commands you used needed another element in the main game loop to update themselves correctly - and if nothing in the loop allows that then the values are stuck.
The loop doesn't freeze tho. It cycles through all the commands, hits the Break Loop at the end, and finishes the loop. But for some reason, all the script calls to add values to variables are being skipped. The Text to Picture function is working, but the values are all 0 instead of the variable input it's supposed to have.

But like I said, if I give it a 1 frame wait, it inputs everything perfectly and displays all the Text to Pictures with the proper information.

It's the weirdest thing.

If I add more functions in-between the Script Calls and the Repeat Loop spot, it again displays all the info correctly. Like with more functions, it has time to run the Scripts. So weird.
Don't know about the technical details, but did you try putting those scripts into the script field of control variable event command?
The Text to Picture function is working, but the values are all 0 instead of the variable input it's supposed to have.
That means either
- the actual values are 0, despite you believing they should be something else
or
- there's a reference to an invalid value in the math, causing the entire formula to zero out

It looks like the top of the event might have been cut off, where do you set the value of variable 87 before you try to reference it in those script calls? What happens if you stick a Show Text inside the loop but above the script showing the value of 87?

The whole Wait part makes me think that you have some other event process that's affecting the same variables, rather than all of it being correctly self-contained in this.
The loop doesn't freeze tho. It cycles through all the commands, hits the Break Loop at the end, and finishes the loop.
that was a general description of what a loop can do if used incorrectly, not that it would apply to your specific loop.
The loop doesn't freeze tho. It cycles through all the commands, hits the Break Loop at the end, and finishes the loop.
I think what Andar is suggesting is that the one wait frame allows the rest of the game to do things in-between loop operations, where it otherwise can't.

I don't know how Text Picture works, but I strongly suspect it only updates once per frame (and not immediately after every plugin command). I'd suggest preparing all the values for it first, then waiting one frame, and then using it to see how it changes.
I think what Andar is suggesting is that the one wait frame allows the rest of the game to do things in-between loop operations, where it otherwise can't.

I don't know how Text Picture works, but I strongly suspect it only updates once per frame (and not immediately after every plugin command). I'd suggest preparing all the values for it first, then waiting one frame, and then using it to see how it changes.
If I setup all the values individually, all the Text to Pictures come out fine. But I think you might be onto something. There's a chance they might have a frame delay built in somehow.

That means either
- the actual values are 0, despite you believing they should be something else
or
- there's a reference to an invalid value in the math, causing the entire formula to zero out

It looks like the top of the event might have been cut off, where do you set the value of variable 87 before you try to reference it in those script calls? What happens if you stick a Show Text inside the loop but above the script showing the value of 87?

The whole Wait part makes me think that you have some other event process that's affecting the same variables, rather than all of it being correctly self-contained in this.
I've tried adding in a Show Text in 2 different ways. So with the Show Text in place, it pops up with the variables all at 0. So my first thought was, okay, I made a mistake somewhere, and the calculation is actually a 0 because my math was wrong somewhere. I couldn't find it. So I added a 1 frame delay in front of the Show Text, and suddenly the text box displays all the variables correctly. If I remove the Text Box and keep the 1 frame delay, the Show Pictures all show properly with the expected variable input.

that was a general description of what a loop can do if used incorrectly, not that it would apply to your specific loop.
Oh no, I wasn't inferring you were telling me I screwed up - just giving you more information just in case it would help.
Each frame, sprites update after [edit: actually before] the interpreter. The TextPicture plugin draws relevant text bitmaps during the sprite update phase (Sprite_Picture#updateBitmap). Your picture texts are based on (the values of variables with IDs equal to the values of) variables 88 and 93, which are changed every loop. So if the loop completes before the sprites update, then all pictures will show the same text.

So, like Mac suggested, a Wait 1 frame could help the variables be the correct values when the text is actually drawn. E.g. immediately after the 3rd showPicture script call?


Also, just a heads-up, I think this is a typo?
JavaScript:
$gameVariables.setValue($gameVariables.value(95),$dataWeapons[$gameVariables.value(87).id]);
.id should be outside the square brackets. (Variable 87 is just a number.)
@caethryil

That is definitely a typo! Thanks for spotting that for me. Odd that it hadn't thrown an error. Interesting.
@Brigg you might want to read through the "Bughunting" tutorial linked in my signature - not for the specifics, but it includes a more complete explanation of what happens with parallel processes and the game loop.

it isn't explicitly mentioned there, but a wait(1) basically allows all other objects in the game loop to be processed first, and the effects of the order on behaviour are discussed there.
@Andar
Okay. That answers several questions. I hadn't consider the Loop I was creating was also working with the game functions themselves. That Parallel was less parallel and more mixed in rather than working simultaneously.

When testing the event, I created a blank test map and an actual ingame map. I had the same results. Essentially, I decided to just deal with the 8 frame delay - 8 because that's how many times the Loop loops. We're talking about .13th of a second here.

The event pulls up a crafting system with Menu's and options I created to look as if it is a default ingame function. Before you get to the page in question, everything pops up just fine - but there was less info to pull up, so I manually entered it all in. For the pages listing all the available items, there's much more info - and it requires several more pages to go through all the weapons and armor. I used loops to copy and paste. Doing this meant, I just changed a handful of header variables, and the loop calculates the rest to create that page's required items, quantity, ID, name, and ingredients required to craft it.

Having headers also meant less places I had to change and risk missing something and create a bug I'd have to hunt down later.

Thank you and everyone else who responded or will respond! I appreciate all of you. @Andar You are a king, and I'm glad you're still around. You were vital in my in-game casino back in 2019 on RPGVXA. Thank you again! 😀
It occurs to me now that you could remove the wait time by using a Script command to set the picture text without the \v[n] text code, so that its value is determined when set rather than when drawn.

E.g. for the \v[\v[88]] text (untested):
JavaScript:
const c = $gameSwitches.value($gameVariables.value(96)) ? "" : "\\c[7]";
PluginManager.callCommand(this, "TextPicture", "set", {
  text: "\\i[112]" + c + $gameVariables.value($gameVariables.value(88))
});
Obviously you don't have to try this, just thought I'd mention it~

Odd that it hadn't thrown an error. Interesting.
Yea, undefined is a "valid" property identifier in JS, e.g. [1,2,3][undefined] returns undefined. 😴

Original thread: https://forums.rpgmakerweb.com/threads/is-there-a-timing-issue-with-loops.168668/