Jump to content
Sign in to follow this  
nullsystems

Sleep gives error?

Recommended Posts

Hi!

Nice n simple...but very annoying !

{_X action ["EJECT",chopper]; sleep 1} forEach _g;

Why does that above, give me Generic Error Code, at |#|sleep 1 ?

{_x action ["eject", chopper _x]; sleep 1} forEach _g;

While the line above, gives an error on |#|forEach. Type String expected, or something like that.

No idea why.

Share this post


Link to post
Share on other sites
Hi!

Nice n simple...but very annoying !

{_X action ["EJECT",chopper]; sleep 1} forEach _g;

Why does that above, give me Generic Error Code, at |#|sleep 1 ?

{_x action ["eject", chopper _x]; sleep 1} forEach _g;

While the line above, gives an error on |#|forEach. Type String expected, or something like that.

No idea why.

; after sleep 1?

Share this post


Link to post
Share on other sites

_troops = (crew heli1) - [driver heli1,gunner heli1,commander heli1];

{unassignVehicle _x; _x action ["EJECT",vehicle _x];sleep 1;} forEach _troops

_troops allowGetIn false

Same again, they eject but no delay. And Generic Error Code, at sleep 1.

Makes no sense.

Thats all thats in the file (eject.sqf), its being called from a Dialog activeText.

Any other ideas?

Share this post


Link to post
Share on other sites

The forEach command is not meant to be used the way you are trying. Delays inside the loop are not allowed, because it wants to execute all commands as quickly as possible.

Try this instead:

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

_troops = (crew heli1) - [driver heli1,gunner heli1,commander heli1];

for [{_x=0},{_x<(count _troops)},{_x=_x+1}] do

{

 unassignVehicle (_troops select _x);

 (_troops select _x) action ["EJECT",vehicle (_troops select _x)];

 sleep 1;

};

_troops allowGetIn false;

Share this post


Link to post
Share on other sites
The forEach command is not meant to be used the way you are trying. Delays inside the loop are not allowed, because it wants to execute all commands as quickly as possible.

Not true.

Using sleep command within forEach loop is perfectly allowed and works - but of course only as long as it is SQF script.

I think the problem here might be, that nullsystems is using SQS instead?

You said you are using SQF script, are you sure? And how are you executing the script?

edit:

In SQF script the following should work perfeclty:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{

_x action ["eject", vehicle _x];

sleep 1

} forEach _g;The problem might also be in the '_g' variable, is it really an array of units?

Because i would use variable named '_g' to reference a group - which is very different than array of units.

ForEach needs array.

Make sure your '_g' variable refers to an array of units - something like (units group _leader), or something like [unit1,unit2,unit3], or something like (crew _vehicle), etc.

Share this post


Link to post
Share on other sites

It is deffinately an SQF.

[] exec "eject.sqf"

Its being executed from that.

Share this post


Link to post
Share on other sites

Right, ive solved it. Thank you

Was a problem with the way it was executed, who would of thought?

Share this post


Link to post
Share on other sites
Right, ive solved it. Thank you

Was a problem with the way it was executed, who would of thought?

Exactly.

It does not matter whether you name your script "myScript.SQS" or "myScript.SQF", the only thing that matters is the way you are executing the script, whether you are using "exec" sommand (which executes the script as an SQS) or "spawn" or "execVM" (which executes the script as an SQF).

Share this post


Link to post
Share on other sites

Right

I appear to of messed it up again.

Can someone explain to me clearly how to get this working:

----------------------

_minheight = 60;

_fromground = getpos heli1 select 2;

?(_fromground <= _minheight): hint 'Eject only above 60m!'; exit;

_troops = (crew heli1) - [driver heli1,gunner heli1,commander heli1];

{

unassignVehicle _x;

_x action ["EJECT",vehicle _x];

sleep 1

}

forEach _troops;

_troops allowGetIn false;

---------------------------

**EDIT** this is telling me that the ?() is invalid. Any idea why ?

Its driving me absolutely raving mad with it. I had it working, I did something and now its not.

Its being executed from a dialog ACTIVETEXT command.

Please, someone help me.

Share this post


Link to post
Share on other sites

You cannot use sleep in forEach.<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">for "_i" from 0 to count _g - 1 do

{

_g select _i action ["EJECT",chopper];

sleep 1;

};

Share this post


Link to post
Share on other sites

Because you aren't using semicolons at the end of each command, i would guess its an SQS script?

If that is true, then you can't spread the forEach loop over multiple lines - it must be on single line like this:

{unassignVehicle _x; _x action ["EJECT",vehicle _x]} forEach _troops

...also, your sleep command has to be inside the curly brackets - or if you are using an SQS script then you can't use the sleep command at all.

Share this post


Link to post
Share on other sites
You cannot use sleep in forEach.<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">for "_i" from 0 to count _g - 1 do

{

_g select _i action ["EJECT",chopper];

sleep 1;

};

You can use sleep inside forEach, if it is an SQF script.

Share this post


Link to post
Share on other sites

Ah, yes. You're using "exec". The file ending does not matter, you could also call them myscript.nullsystems wink_o.gif If you want to use sqf syntax, you have to execVM or spawn it, if you want to use the old sqs syntax, you have to exec it.

/edit: @5133p39: Ah, okay. That can be correct. (Please edit your posts, do not double-post).

Share this post


Link to post
Share on other sites

lmao

err..nice explanations.

Ok, so to use the SLEEP we need it SQF.

Im getting errors:

; required at both var callings at the top.

Then it tells me the ?() doesnt work.

Can someone help me out?

I know im being an idiot, but at this point im very very annoyed over it lol

Share this post


Link to post
Share on other sites

LOL, I better should have read every single post... sorry 5133p39, you explained it already... whistle.gif

Share this post


Link to post
Share on other sites

After I fixed the ; at the two first lines.

It tells them INVALID NUMBER EXPRESION.

|#|?(_fromground <= _minheight): hint 'Eject only above 60m!'; exit;

So, whats going on there now ?

Share this post


Link to post
Share on other sites

nullsystems

I think it'll be easier for us if you also post the way you execute/start your script.

I found out some stuff about the sleep thing.

.sqs doesn't seem to support "~1" which is the sqs "sleep" in forEach

(this I knew already)

calling a function directly from a trigger or init doesn't work as

what will wait for the function to be ready?

if you want to be able to sleep a function you need to execute/start it from another script

e.g.

trigger

nil = heli1 execVM "omgScript.sqf"

omgScript.sqf

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

myFuctionRetValue = heli call compile "sleepFunction.sqf";

hint format["%1",myFuctionRetValue ]; //will be 10

sleepFunction.sqf

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

_heli = _this;

{

//eject troops

sleep 1;

}forEach crew _heli;

10

If you want to use a script that has sleeps/waitUntil in them from init-lines or triggers use

spawn or execVM

[edit]

also, if you would like ot post your script as it is now, along with how you execute/start it?

Share this post


Link to post
Share on other sites
After I fixed the ; at the two first lines.

It tells them INVALID NUMBER EXPRESION.

|#|?(_fromground <= _minheight): hint 'Eject only above 60m!'; exit;

So, whats going on there now ?

Look, many commands and things depends on whether you are using SQS or SQF.

So are you now using SQF? then you can't use the SQS ? conditions, use the if/then/else instead.

Read through the wiki, all those basics are there.

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  

×