Jump to content
cash

"WHILE" do not working !

Recommended Posts

I placed two soldier in editor . 1-st named sol , 2-nd named sol1, placed a trigger : activation Radio "alfa" , in the init field of a trigger has write following code : while {alive sol1} do { sol doMove (position sol1);} ,command doMove is running once but not loop .
May be it's my mistake , if somebody know what how to fix the problem  , i'll be grateful for any help.

Share this post


Link to post
Share on other sites

You might need to spawn your code.

Try this :

0 = [] spawn {
	while {alive sol1} do {
		sol doMove (position sol1);
		sleep 1;
	};
};
EDIT : ...wait, what do you mean "init field of a trigger", did you mean the on Act field?

Share this post


Link to post
Share on other sites

while is limited to 10000 loops in unscheduled environment, which trigger on Act is, so do what haleks said

Share this post


Link to post
Share on other sites

As an additional "spawning" the code converts it from the unscheduled environment to the scheduled and will not halt at 10,000 iterations. It will be "infinite" for as long as the condition remains true.

Share this post


Link to post
Share on other sites

You might need to spawn your code.

Try this :

0 = [] spawn {
	while {alive sol1} do {
		sol doMove (position sol1);
		sleep 1;
	};
};
EDIT : ...wait, what do you mean "init field of a trigger", did you mean the on Act field?

 

Thank you very much , it is working now . But anyway i am not understand why this code is not working without "spawn". i am use this code same as bohemia wiki example and there no any "spawn" argument. They should did more advanced example of usage their commands .

Share this post


Link to post
Share on other sites

i think u should learn something about scheduled and non-scheduled environment cause thats the key of ur mistake.
there is no need to discuss that for every given example at the wiki.

also killzone kid explains the problem on the notes of the wiki page

 

useful links:

 

killzone kids scripting tutorial

 

BI wiki - code optimization

  • Like 1

Share this post


Link to post
Share on other sites

They should did more advanced example of usage their commands .

 

There are several ways how and where those commands can be used, so it really depends. The biki just shows the command in its most basic form.

 

 

Simply put, you can't use endless loops directly in init because all init-code needs to finish before the mission starts.

  • 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

×