Jump to content
Sign in to follow this  
mtlgd

error "missing {"

Recommended Posts

I can't figure out how to structure script properly.<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">switch (Param1) do

{

   case 0:

   {

code;

   };

   case 1:

   {

code;

   };

   

};

This is an extract of code that I know works, taken from another script that was downloaded, however when I try to structure my scripting this way, I get the error "missing {".

The code itself is good, I can pull it all up to one line and it executes perfectly, but then its six miles long and dificult to read. I've tried using several editors which all insert CRLF characters at the end of the line. however they also show those characters in the sample script also (unless its an editor shortcoming).

Any suggestions? I found a discussion about editors and have tried most of them an they all seem to do it. This is the code, in its prefered structure. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">switch (_p2) do

{

   case 32:

   {

if ((MyVecX >= 0) and (MyVecX < 1) and (MyVecY <= 1 ) and (MyVecY > 0)) then {MyVecX = MyVecX + _mySin; MyVecY = MyVecY - _mySin};

if ((MyVecX > 0) and (MyVecX <= 1) and (MyVecY <= 0 ) and (MyVecY > -1)) then {MyVecX = MyVecX - _mySin; MyVecY = MyVecY - _mySin};

if ((MyVecX <= 0) and (MyVecX > -1) and (MyVecY >= -1 ) and (MyVecY < 0)) then {MyVecX = MyVecX - _mySin; MyVecY = MyVecY + _mySin};

if ((MyVecX >= -1) and (MyVecX < 0) and (MyVecY >= 0 ) and (MyVecY < 1)) then {MyVecX = MyVecX + _mySin; MyVecY = MyVecY + _mySin};

   };

   case 30:

   {

if ((MyVecX > -1) and (MyVecX <= 0) and (MyVecY <= 1 ) and (MyVecY > 0)) then {MyVecX = MyVecX - _mySin; MyVecY = MyVecY - _mySin};

if ((MyVecX >= -1) and (MyVecX < 0) and (MyVecY <= 0 ) and (MyVecY > -1)) then {MyVecX = MyVecX + _mySin; MyVecY = MyVecY - _mySin};

if ((MyVecX >= 0) and (MyVecX < 1) and (MyVecY >= -1 ) and (MyVecY < 0)) then {MyVecX = MyVecX + _mySin; MyVecY = MyVecY + _mySin};

if ((MyVecX <= 1) and (MyVecX > 0) and (MyVecY >= 0 ) and (MyVecY < 1)) then {MyVecX = MyVecX - _mySin; MyVecY = MyVecY + _mySin};

   };

};

As you can see, with all of it on one line its hellishly hard to read.

Both files are .sqf format.

Mtl

Share this post


Link to post
Share on other sites

Add your code line by line and tell us at which point you get the error.

€: Oh yes, right taurus. I didn't see that. If you are still getting errors do what I suggested.

Share this post


Link to post
Share on other sites

The only thing I see that you might have missed is the last ;

after each line.

i.e.

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

{

if ((MyVecX >= 0) and (MyVecX < 1) and (MyVecY <= 1 ) and (MyVecY > 0)) then {

MyVecX = MyVecX + _mySin; MyVecY = MyVecY - _mySin;

};

if ((MyVecX > 0) and (MyVecX <= 1) and (MyVecY <= 0 ) and (MyVecY > -1)) then {

MyVecX = MyVecX - _mySin; MyVecY = MyVecY - _mySin;

};

if ((MyVecX <= 0) and (MyVecX > -1) and (MyVecY >= -1 ) and (MyVecY < 0)) then {

MyVecX = MyVecX - _mySin; MyVecY = MyVecY + _mySin;

};

if ((MyVecX >= -1) and (MyVecX < 0) and (MyVecY >= 0 ) and (MyVecY < 1)) then {

MyVecX = MyVecX + _mySin; MyVecY = MyVecY + _mySin;

};

};

The compiler doesn't always show exactly what is wrong.

Share this post


Link to post
Share on other sites

Are you sure you are running the script with execVM? (and not exec, which is for SQS)

Do all variables that you use down there exist and have valid numbers?

is the _p2 variable defined as a private variable? (aswell as the others with _)

private ["_p2"];

Read ur text now a couple of times but don't spot any typo yet :S

The compiler might tell you in the arma.rpt which row is the error,.

@Taurus, those ; are unnececairy before the }; because it's on 1 line smile_o.gif

Share this post


Link to post
Share on other sites
@Taurus, those ; are unnececairy before the }; because it's on 1 line smile_o.gif

Ye, I just realized, but I didn't want to edit my post "again" biggrin_o.gif

Anyways, I think its like sickboy is saying, check how you start the script.

Also, I don't think switches are allowed when calling upon an function from an init-line. confused_o.gif I don't recall.

Share this post


Link to post
Share on other sites
Are you sure you are running the script with execVM? (and not exec, which is for SQS)

Bingo!!

Thanks a lot, six miles worth, my sanity is preserved!!

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  

×