-)rStrangelove 0 Posted April 4, 2007 Hey guys, i surely wouldn't post this normally but i'm at my wits end. Â 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? Â [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
nuxil 2 Posted April 4, 2007 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
t_d 47 Posted April 4, 2007 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
igor drukov 0 Posted April 4, 2007 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
-)rStrangelove 0 Posted April 5, 2007 Nice 1 Igor, thx! 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
igor drukov 0 Posted April 5, 2007 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
-)rStrangelove 0 Posted April 7, 2007 Still doesn't work. This sqf stuff with call/execVM/spawn is pretty confusing. Share this post Link to post Share on other sites
shuko 59 Posted April 7, 2007 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
-)rStrangelove 0 Posted April 7, 2007 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. 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. 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. Share this post Link to post Share on other sites
shuko 59 Posted April 7, 2007 )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