Jump to content
Sign in to follow this  
MichaelGER

While loop runs just once

Recommended Posts

part of the code:

_timedone = 0;
_timestep = (planttime/100);

while {(alive _caller) && ((_caller distance _com) < plantdistance) && (_timedone < planttime) && (alive _com)} do
{
_timedone = _timedone + _timestep;
if (debug) then
{
	diag_log _timedone;
};

if (isMultiplayer) then
{
	[nil,nil,rHINT, format ["%1 percent",_timedone]] call RE;
} else {
hint format ["%1 percent",_timedone];
};
sleep _timestep;
};

The planttime is 30 seconds.

The while loop runs once (hint tells me 0.3 percent) but then it stops. Altough im still alive, at the same position,.... it stops after the first loop.

the script is called via addaction. the action is added to the com.

_com = _this select 0;
_caller = _this select 1;

any ideas why the loop runs just once?

Share this post


Link to post
Share on other sites

what is platdistance? I mean I know what it should be, but what is it really?

edit: lol, Kylania needed 2 mins less to read it. :)

Share this post


Link to post
Share on other sites

plantdistance is just a var that has the value 5. is just means that the caller of the action must be closer than 5 meters to the com.

Share this post


Link to post
Share on other sites

Are you sure you are allowed to sleep in an action ? You might want to spawn rather than call that code. Anything in the rpt file ?

Share this post


Link to post
Share on other sites

Why don't you output by a hint the elements of the three conditions after sleep and see what their values are?

(You can also check if sleep works at all. :))

Share this post


Link to post
Share on other sites

Not sure with the sleep. Is there a difference between a script that is called via addaction and a normal exec(VM)?

No errors in the .rpt. And squint also cant find an error.

E: @zapat:

while waiting for answers ive done that.

diag_log [(alive _caller),((_caller distance _com) < plantdistance),(_timedone < planttime),(alive _com)];

result is:

[bool,bool,true,true]

Share this post


Link to post
Share on other sites

Returns "bool" if the object doesn't exists...

Should be true,true,true,true, so passing _com and _caller not succeeded. Where have you put _com = ... and _caller=... ?

(And I use sleep in sqf called by addAction, and it works the same as a execVM sqf for me.)

Edited by zapat

Share this post


Link to post
Share on other sites

E: nvmd

changed _caller to player fixed it :)

thx for help guys.

Edited by MichaelGER

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
Sign in to follow this  

×