Scripts / while loop problem

Author
Message
Bolt Action Gaming
GameGuru Tool Maker
10
Years of Service
User Offline
Joined: 24th Oct 2013
Location: Harrisburg, PA (USA)
Posted: 4th Feb 2017 04:00 Edited at: 4th Feb 2017 04:24
So I'm trying to build a simple while loop.
It's just something like this:




So if you're wondering why I have the if whileindex and the break in there it's because the loop wasn't breaking on it's own.

So here's what happens:

You run the loop -
it gets to 100, never goes higher, locks in the loop.
So I added the break right? Added it and set it to 99.
Annnnd same thing, only this time the debug prompt shows it stopping at 98.
It never actually exits the loop.
Any thoughts?
Bolt Action Gaming
GameGuru Tool Maker
10
Years of Service
User Offline
Joined: 24th Oct 2013
Location: Harrisburg, PA (USA)
Posted: 4th Feb 2017 04:23

More weird behavior.
So the original version of the loop looked like this:


*HOWEVER* if I uncomment the upper whileindex=whileindex + 1 variable... it works. Or rather, the 'do stuff' portion works and you don't get completely locked up. BUT - it never actually exits the loop in the proper sense. it just stays at 99 forever and never leaves. This is all handled by a trigger 'player in zone' main script.

Bolt Action Gaming
GameGuru Tool Maker
10
Years of Service
User Offline
Joined: 24th Oct 2013
Location: Harrisburg, PA (USA)
Posted: 4th Feb 2017 04:25
I feel like this is some kind of game-guru lua nuance I'm not familiar with and if I just knew what it was, I'd have it. Anyways, that should cover it for now. Thanks for any thoughts/comments.
AmenMoses
GameGuru Master
8
Years of Service
Recently Online
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 4th Feb 2017 05:09 Edited at: 4th Feb 2017 05:10
In a year of Lua scripting I don't think I've used a while loop!

I would suggest making whileindex local as a start but I'll play around later to see if I can replicate your issues.
Been there, done that, got all the T-Shirts!
PM
Bolt Action Gaming
GameGuru Tool Maker
10
Years of Service
User Offline
Joined: 24th Oct 2013
Location: Harrisburg, PA (USA)
Posted: 4th Feb 2017 05:16
thanks. I suppose maybe it's calling it over and over because it's in a trigger box, so localizing might help - will let you know.

AmenMoses
GameGuru Master
8
Years of Service
Recently Online
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 4th Feb 2017 06:30
Ahh, I see the problem, the Prompt is only showing the last value, it isn't getting stuck in the loop it is just executing the whole loop every frame but you will only see the final value in the Prompt output.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 4th Feb 2017 09:23
If you use a while you are literally stuck inside it until it completes, there's no sync or update to the engine etc in that cycle so it will just appear locked up if the while never completes or takes too long.

Amen is right that it will only prompt the final value because as I say, there's nothing in there to tell it how to display that prompt (the engine handles all syncing behind the scenes normally).

With the above limit and as scripts are called every frame its not generally a good idea to call while or repeat until (unless for very quick things you're sure will exit) as this will result in hang ups or even full lock up (in appearance at least).

What exactly are you trying to do? I'm sure it can be achieved with a different method.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Bolt Action Gaming
GameGuru Tool Maker
10
Years of Service
User Offline
Joined: 24th Oct 2013
Location: Harrisburg, PA (USA)
Posted: 4th Feb 2017 18:54
I'll send you a PM smallg.


Login to post a reply

Server time is: 2024-05-04 10:25:17
Your offset time is: 2024-05-04 10:25:17