How can I run a script a set number of times then stop?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

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
Fragger
Posts: 42
Joined: Sat Mar 19, 2022 11:59 am
Graphics Processor: Intel (Modern GZDoom)

How can I run a script a set number of times then stop?

Post by Fragger »

I need a loop, but my knowledge is limited. I need to move an actor in one unit increments, and writing the same line 64 times seems too much.
Maybe someone knows how to do it, or can point me to a tutorial. The examples in the wiki don't help.

Thanks.
Jarewill
 
 
Posts: 1854
Joined: Sun Jul 21, 2019 8:54 am

Re: How can I run a script a set number of times then stop?

Post by Jarewill »

For that you will want to use loops.
In this case for will help you:

Code: Select all

for(int i=0; i<64; i++){
	//Do code here
}
This loop will run 64 times and then stop.
Fragger
Posts: 42
Joined: Sat Mar 19, 2022 11:59 am
Graphics Processor: Intel (Modern GZDoom)

Re: How can I run a script a set number of times then stop?

Post by Fragger »

So, it's:
Script 1 (void)
for(int i=0; i<64; i++)
{
//Do code here
}
Jarewill
 
 
Posts: 1854
Joined: Sun Jul 21, 2019 8:54 am

Re: How can I run a script a set number of times then stop?

Post by Jarewill »

Scripts must also have opening and closing brackets.
Also you might want a Delay in your loop so it doesn't execute all at once.

Like so:

Code: Select all

Script 1 (void)
{
	for(int i=0; i<64; i++)
	{
		//Actions here
		Delay(1); //Delay by 1 tic if needed
	}
}
Post Reply

Return to “Scripting”