How big a variable for a While loop until the ACS script is a runaway?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Enjay
 
 
Posts: 27376
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

How big a variable for a While loop until the ACS script is a runaway?

Post by Enjay »

This thought occurred to me while (ahem) working on a map in which I have a script with a "while" loop that repeats 20 times before moving on: "I know that GZDoom will error out with an infinite loop, but how big can the variable be before GZDoom treats the script as a runaway - even though it isn't infinite?"

This is purely out of interest because I suspect it's a huge number and well beyond any practical use but it would just be something nice to know.

So, in a situation like this, how big would "HypotheticalVariable" have to be before GZDoom noped out and reported a runaway script?

Code: Select all

Script "HypotheticalScript" (void)
{
	int HypotheticalVariable=999;
	While(HypotheticalVariable>0)
	{
		DoSomeStuffWithNoDelays();
		HypotheticalVariable--;
	}

	DoMoreStuff();
}
I know it isn't 10s (even Vanilla Hexen does that every time a window is shattered), it's not a few hundred, because I've done it to iterate through all the tagged sectors in a map to change light levels, and there were a quite lot of tag numbers on the map. So, is it thousands, millions, billions, more? Does it depend on something else - like system specs?
User avatar
phantombeta
Posts: 2197
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: How big a variable for a While loop until the ACS script is a runaway?

Post by phantombeta »

The runaway limit is fixed and based on the number of instructions executed by the script since it began executing, and it takes 2000000 instructions until the script gets killed off by GZDoom. (That means the code before and between loops counts for the limit too)
Different things in the code also take different amounts of instructions (HUDMessage stuff in particular takes a LOT of instructions!), so it's pretty much impossible to estimate how many iterations a loop can perform.

And of course, as you may know, "waiting" or restarting the script will reset the runaway loop counter.
User avatar
Enjay
 
 
Posts: 27376
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: How big a variable for a While loop until the ACS script is a runaway?

Post by Enjay »

Ah, OK. So it's not just dependent on the loop, but everything that the script has done up to that point. That makes sense. Thank you.

So, just thinking aloud, if one script started a second or multiple scripts, that each had a loop of this kind, would they be counted as one big thing, or several separate things?

i.e. if there was a script like this:

Code: Select all

Script "HypotheticalScriptMaster" (void)
{
	ACS_NamedExecute("HypotheticalScript01", 0, 0, 0, 0);
	ACS_NamedExecute("HypotheticalScript02", 0, 0, 0, 0);
	ACS_NamedExecute("HypotheticalScript03", 0, 0, 0, 0);
	ACS_NamedExecute("HypotheticalScript04", 0, 0, 0, 0);
	ACS_NamedExecute("HypotheticalScript05", 0, 0, 0, 0);
	ACS_NamedExecute("HypotheticalScript06", 0, 0, 0, 0);
	ACS_NamedExecute("HypotheticalScript07", 0, 0, 0, 0);
	ACS_NamedExecute("HypotheticalScript08", 0, 0, 0, 0);
	ACS_NamedExecute("HypotheticalScript09", 0, 0, 0, 0);
	ACS_NamedExecute("HypotheticalScript10", 0, 0, 0, 0);
	ACS_NamedExecute("HypotheticalScript11", 0, 0, 0, 0);
	ACS_NamedExecute("HypotheticalScript12", 0, 0, 0, 0);
	ACS_NamedExecute("HypotheticalScript13", 0, 0, 0, 0);
	ACS_NamedExecute("HypotheticalScript14", 0, 0, 0, 0);
	ACS_NamedExecute("HypotheticalScript15", 0, 0, 0, 0);
	ACS_NamedExecute("HypotheticalScript16", 0, 0, 0, 0);
}
and each one of the numbered hypothetical scripts had a while loop, would they all be counted as part of one script, or separately - or is this something else entirely?

I'm not trying to break anything, or do anything daft BTW. I'm just trying to learn stuff.
User avatar
phantombeta
Posts: 2197
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: How big a variable for a While loop until the ACS script is a runaway?

Post by phantombeta »

They would not count towards the limit. The limit is for the execution of each individual script.
User avatar
Enjay
 
 
Posts: 27376
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: How big a variable for a While loop until the ACS script is a runaway?

Post by Enjay »

That clears that up then.
Thank you for your help, much appreciated.
Post Reply

Return to “Scripting”