Jump to content
Sign in to follow this  
-)rStrangelove

Can't use SLEEP in my sqf

Recommended Posts

Hey guys, i surely wouldn't post this normally but i'm at my wits end.  crazy_o.gif

I wrote a little marker search function (it returns indexed markers in an array), but i can't use the sleep command in it - it always says:

Quote[/b] ]

...

#Sleep 1;

Error Generic error in expression ...

...

This is the complete code:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_goaltype","_goalarray","_continue","_i","_goal"];

_continue = TRUE;

_goaltype = _this;

_goalarray = [];

Sleep 1;

_i = 1;

while {_continue}do

{

//setup marker+index:

_goal = format["%1_%2",_goaltype,_i];

//if marker exists:

if (getmarkerpos _goal select 0 > 0) then

{

//if marker isnt deactivated AND marker is free:

if ((getmarkerpos _goal select 0 > 1) AND (getmarkersize _goal select 0 == 0.5)) then

{

//marker is valid:

_goalarray = _goalarray + [_goal];

_i = _i + 1;

} else

{

//skip this marker:

_i = _i + 1;

};

} else

{

_continue = FALSE;

};

};

//RETURN

_goalarray

The function is called from my init.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

allGoals = compile PreProcessFile "doc\allGoals.sqf"

~0.5

_myarray = "DOC_Wcheck" call allGoals;

Can someone help me plz?  icon_rolleyes.gif

[EDIT]

I know SLEEP makes no sense at the place you see it now, it's supposed to be in the while loop. But no matte where i place it, the error comes again. UBERweird.

Share this post


Link to post
Share on other sites

Hi. im no expert in scripting but,, what if you change while {_continue} to while {(_continue == TRUE)} do { blah blah

i know should not mattre.. but you can give it a try.. i also suspect that the error is related to

_goalarray = _goalarray + [_goal]; but not sure..

have you tryed it another way forexample

_goalarray set [iNDEX, _goal]

_goalarray resize _x+1

i also noticed that at the end of your script your missing a ;

//RETURN

_goalarray <---

Share this post


Link to post
Share on other sites

You cant use sleep or waitUntil in functions that are executed with call. You have to use spawn or execVM instead, but with this method you cant return a value.

Share this post


Link to post
Share on other sites

Hello there

To cut a long story short: convert your init.sqs into an init.sqf (with appropriate syntax).

You can use sleep with call but not from .sqs scripts.

The long story can be found here.

Hope that helps,

Igor.

Share this post


Link to post
Share on other sites

Nice 1 Igor, thx! smile_o.gif

Sooo, the way i see it i dont need a sleep command since my function is very short anyway.

Share this post


Link to post
Share on other sites

Well I'd say your sleep command here is a remnant of good OFP scripting caution no longer (that) necessary with ArmA.

On a sidenote - but you may already be aware of it - if you call your script, all parallel operations will be stopped until completion of the code (more details in our long story). If you spawn it, it will be run in parallel. This is cool, because you can prioritise scripts.

Share this post


Link to post
Share on other sites

Following code gives no error about sleep. Didnt check if rest of it works, just the sleep thing.

Init.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

allGoals = compile PreProcessFile "allGoals.sqf";

sleep 0.5;

_myarray = "DOC_Wcheck" call allGoals;

allGoals.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

private ["_goaltype","_goalarray","_continue","_i","_goal"];

_continue = TRUE;

_goaltype = _this;

_goalarray = [];

sleep 1;

_i = 1;

while {_continue} do {

_goal = format["%1_%2",_goaltype,_i];

if (getmarkerpos _goal select 0 > 0) then {

if ((getmarkerpos _goal select 0 > 1) AND (getmarkersize _goal select 0 == 0.5)) then {

_goalarray = _goalarray + [_goal];

};

_i = _i + 1;

} else {

_continue = FALSE;

};

};

_goalarray

Share this post


Link to post
Share on other sites

Thx mate, dunno wot i was doing wrong. Typo maybe.

[edit]

Actually, this is the wrong approach for me. I want scripts running in parallel AND returning a value.

tounge2.gif

What i have in mind is the following concept:

- there are several groups per side (West,East,Guer,Civ)

- there are indexed markers for every side (Westmarker_1 - x, Eastmarker_1 - x, etc...)

- there's a script running for every group (defining that grp's behaviour) searching for appropiate markers

Groups are changing the values of their markers, so at runtime only 1 group of 1 side may search & change a marker to avoid errors.

In the past i had sync problems like: if westgroup1 is changing a westmarker while westgroup2 is checking all westmarkers, westgroup2 may read outdated markervalues and everything goes to hell. tounge2.gif

I synced everything by setting a global WestFlag to TRUE or FALSE. Every westgroup searching for westmarkers had to aquire the flag first by locking it and then have it unlocked when the marker operations were over. Worked pretty well.

Now i want to port this concept to SQFs. smile_o.gif

Share this post


Link to post
Share on other sites
)rStrangelove @ April 07 2007,15:34)]Actually, this is the wrong approach for me. I want scripts running in parallel AND returning a value.

Then just make the script/loop update a global var

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  

×