Jump to content
Sign in to follow this  
tophe

Getting weird interupted loop in SQF

Recommended Posts

I just started fiddling with SQF. And of course I ran into problems.

In the middle of my script i have this part:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while {alive _unit} do

{

_y = random _x;

_t = random (5)+5;

_unit doMove (_house buildingpos _y);

if (alive _unit) then {waitUntil {unitready _unit}};

sleep _t;

};

This works really good.. for a while.

The unit will randomly move around. But after a few minutes he will just stop. I tried putting a sleep 1 between every line to give it some space but the same result happens.

The line that gets frozen are "if (alive _unit) then {waitUntil {unitready _unit}};"

I have tried using only "waitUntil {unitready _unit};" but that won't let me get out of the loop if the unit is dead. It seems the unitready command is still returning false if the unit dies without fiinishing it's last task.

I tried adding a hint after the While loop so I know that it does work. If the unit is killed the loop will end.

But when the unit has stopped moving the loop is not ended if the unit is killed. This happens randomly. Sometimes after 1 minute, sometimes after 5 minutes. Is the unitReady command unstable?

Share this post


Link to post
Share on other sites

well the while command has a limit of 10000 iterations then it will exit automatically. With an FPS count of about 20 this will run about 8 Minutes then.

To overcome this limit use either double while loops (will exit after 10000^2 iterations --> about 58 days with 20 FPS) or use a for loops like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">for [{_i = 0},{_i < 1},{_i = _i}] do {

};

(I don't know for sure if this for loop will exit at one point or not but I never played long enough to reach such a point so it seems to run forever)

Share this post


Link to post
Share on other sites
Quote[/b] ]The line that gets frozen are "if (alive _unit) then {waitUntil {unitready _unit}};"

I have tried using only "waitUntil {unitready _unit};" but that won't let me get out of the loop if the unit is dead. It seems the unitready command is still returning false if the unit dies without fiinishing it's last task.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">waitUntil {(unitready _unit) || !(alive _unit)};

You don't need the if-then since you can put any number of conditions in the waitUntil command.

Share this post


Link to post
Share on other sites

Donnervogel:

Quote[/b] ]Posted on Mar. 10 2007,03:05well the while command has a limit of 10000 iterations then it will exit automatically. With an FPS count of about 20 this will run about 8 Minutes then.

It never reaches 10000. Since the loop is held up until the unit has finished the command. It freezes at the waitUntil command.

It seems that the unit suddenly stops reporting that it's finished with the move command.

I'll try Kyle's sollution.

Share this post


Link to post
Share on other sites

Nope, it didn't work. The script freezes at the waitUntil command. It freezes randomly... could be after 2 loops or 30.. It's just random. Same result with Donnervogel sollution.

There must be a bug in the waitUntil command or some bug when the unit reports that it's finished with the move command.

Share this post


Link to post
Share on other sites

Freezing scripts (as in completely freezing ArmA) are normaly a sign of endless loops without using "sleep" in them.

Share this post


Link to post
Share on other sites

Well this problem is due to the fact that there is a bug. I got it confirmed at the buglist. Units sometimes won't report that they have finished a move command inside buildings. Thus the script freezes at the WaitUntil line since the script never recieves instructions that the condition is set to TRUE.

The problem is a bug. So there is nothing I can do until they fix it. I will have to use somekind of getpos thingy tp get the script to report back when the unit is at its destination.

Share this post


Link to post
Share on other sites
well the while command has a limit of 10000 iterations then it will exit automatically.

For new type scripts this limitation shouldn't appear anymore since build 5134. smile_o.gif

Share this post


Link to post
Share on other sites
Well this problem is due to the fact that there is a bug. I got it confirmed at the buglist. Units sometimes won't report that they have finished a move command inside buildings. Thus the script freezes at the WaitUntil line since the script never recieves instructions that the condition is set to TRUE.

The problem is a bug. So there is nothing I can do until they fix it. I will have to use somekind of getpos thingy tp get the script to report back when the unit is at its destination.

You could keep the code I gave you but add a timeout condition (so the waituntil exits after X amount of seconds if the other conditions aren't met).

Share this post


Link to post
Share on other sites

good idea.

What syntax do I use? I would need some kind of waitUntil {unitready} or {timeout 10}

if you catch my drift...

Share this post


Link to post
Share on other sites
well the while command has a limit of 10000 iterations then it will exit automatically.

For new type scripts this limitation shouldn't appear anymore since build 5134. smile_o.gif

i can confirm that with ArmA version 1.05 (build 5136), the limit is either gone, or much much more higher.

I succesfully tested it with 2000000 iterations (could do much more, but i am happy with 2000000).

Share this post


Link to post
Share on other sites
well the while command has a limit of 10000 iterations then it will exit automatically.

For new type scripts this limitation shouldn't appear anymore since build 5134. smile_o.gif

i can confirm that with ArmA version 1.05 (build 5136), the limit is either gone, or much much more higher.

I succesfully tested it with 2000000 iterations (could do much more, but i am happy with 2000000).

oh that is cool.

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  

×