Jump to content
Sign in to follow this  
SkogUlv

IF THEN logic/syntax problem

Recommended Posts

Its late but I dont really know what I am doing wrong with IF THEN logic in ArmA.

Example:

_test = 2;

_work = 2;

If ( _work==1 ) then { hint "work ok" } else { hint "work not ok" };

If ( _test==2 ) then

{

hint "2";

} else

{

hint "not 2";

};

First IF with _work proceeds ok, second with _test fails and gives error :

'|#|};'

Error missing {

No matter how I try stack / add { } I run into same error message.

Anyone able to help out with a proper working example ?

Thanks in advance,

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

Share this post


Link to post
Share on other sites

You're probably using exec to execute your script. Script syntax is other than function syntax. Try execVM, for more questions check the respective entries of the community wiki.

Share this post


Link to post
Share on other sites

I've spent hours in the wiki without getting any closer to a solution ;-(

And yes I am using [ this ] exec "myscript.sqs" ..

The info in the wiki about exec / execvm etc doesnt tell me much , any better documentation arround ?

Share this post


Link to post
Share on other sites
I've spent hours in the wiki without getting any closer to a solution ;-(

And yes I am using [ this ] exec "myscript.sqs" ..

The info in the wiki about exec / execvm etc doesnt tell me much , any better documentation arround ?

If you're using exec you have to write it all in a line. With execVM you don't have to.

Share this post


Link to post
Share on other sites

Exactly, with just [] exec "script.sqs", the end of a line is actually the end of a command.

That means ofp/arma is looking at it like this:

command: If ( _test==2 ) then

command: {

command: hint "2";

command: } else

command: {

command: hint "not 2";

command: };

Which is why you're only seeing the error on the last bit there, because ofp at least, only displays 1 line of error messages.

If it displayed them all, there would be an error in all but the hint lines.

Share this post


Link to post
Share on other sites
I've spent hours in the wiki without getting any closer to a solution ;-(

And yes I am using [ this ] exec "myscript.sqs" ..

The info in the wiki about exec / execvm etc doesnt tell me much , any better documentation arround ?

If you're using exec you have to write it all in a line. With execVM you don't have to.

Thanks for that info.

However I still can't get this to work out, can I ask you to provide me with a -working- solution (before I turn nuts hehe).

If I try on a unit (init field) to add:

this execVM "max.sqf"

Then I receive error message "type script, expected nothing"

guess I tried tons of variations there but still no go with execVM, and I been checking the wiki back & forth x times without help.

Share this post


Link to post
Share on other sites

Looks like execVM can't be called directly in the editor since the syntax check doesn't recognize it properly.

You would either have to use exec to call a script that itself can use execVM, or Structure your script in the way that was described by the others and call it directly with the exec command in the editor.

Using execVM in a script and not in the editor works fine here.

Share this post


Link to post
Share on other sites

In the editor you have to do it like this:

s = [] execVM "script.sqs"

s is a dummy variable that makes the code parser in the editor happy. I had to do that for a vehicle respawn script that execs it from the init field of the vehicle.

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  

×