Jump to content

Recommended Posts

This might be a stupid question but is it possible to do a "while{} do {}" or "for{}do{}" or "if{}then{}" loop that executes the code during a specified amount of time

Share this post


Link to post
Share on other sites
for "_i" from X to Y do {}

If X == 0, Y == 9, it'll execute 10 times

  • Like 1

Share this post


Link to post
Share on other sites
8 minutes ago, notproplayer3 said:

This might be a stupid question but is it possible to do a "while{} do {}" or "for{}do{}" or "if{}then{}" loop that executes the code during a specified amount of time

 

Something like this maybe?

_test = [] spawn {

	_duration = 10;
	_timeOut = time + _duration;

	while {time < _timeOut} do {

		systemchat format ["The time is: %1",round time];
		sleep 1;
                       
	};
                           
	systemchat "Done.";

};

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Yes, indeed it works, to be honest I thought there was some command in the game that made this more simple to do, but I won't complain more, anyways thanks a lot to all of you

Share this post


Link to post
Share on other sites

You can also use a boolean variable. Something like:

someVariable = true;
while {someVariable} do // while someVariable is true
{
	// code
	sleep 10;
};

In another file set to false. This method may not be the best approach, all depends on what you are doing and where, in which files, etc...

Another way is for loop with step (set to 10 or whatever). Check Wiki.

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×