Home   Help Search Login Register  

Author Topic: if, while not working when indented  (Read 526 times)

0 Members and 2 Guests are viewing this topic.

Offline Razorwings18

  • Contributing Member
  • **
  • I'm NOT a llama. I checked.
if, while not working when indented
« on: 13 Mar 2003, 08:55:47 »
I used to script up till v1.2 and then lost interest.
Now I'm getting back to scripting at v1.90 and I found some really nice new scripting commands, like "if" and "while" instead of those ugly "?" and "goto".

Now, when I try to use "if" in a script, the following single-line works perfectly:

Code: [Select]
if (((getMarkerPos _markername) select 0)<_MAPHALFX) then{_strowner = "R";}else{_strowner = "B";};
but when I try to indent it so it's more readable like this:

Code: [Select]
if (((getMarkerPos _markername) select 0)<_MAPHALFX) then
{
    _strowner = "R";
}
else
{
    _strowner = "B";
};

It gives me a "|#|};': Error Invalid Number in Expression" error.
Same happens with "while". All variables involved are declared. All lines in the script are properly ended by a semicolon.

Any help would be appreciated; I can't find anything on it in OFPEC or CM's site.

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:if, while not working when indented
« Reply #1 on: 14 Mar 2003, 01:21:22 »
Hmm...

I suggest it's because OFP doesn't like indents or new lines in .sqs files. The exception to this being .ext files, in which I'm pretty sure indenting etc. is fine :)

You have to remember that OFP isn't C++ or any other language, it's kind of a hybrid and has some fairly interesting peculiarities, this most probably being one of them ;)

I think to solve the problem you just need to keep the statement on the same line...

Offline Razorwings18

  • Contributing Member
  • **
  • I'm NOT a llama. I checked.
Re:if, while not working when indented
« Reply #2 on: 14 Mar 2003, 03:14:23 »
Thanks for your reply, sui.
I'd be prone to say what you're suggesting is the case if it wasn't that I've found working indented if/while clauses on 3rd party functions (sqf)...
Now that I think of it... could it be that those commands can only be indented within functions yet not on the main script?

I'll give it a try in the meantime, but that'd be REALLY shady...

Offline Ranger

  • Members
  • *
  • Hoo-ah!
Re:if, while not working when indented
« Reply #3 on: 14 Mar 2003, 18:51:46 »
Your guess is correct.  You can only indent code in .sqf files, but not in .sqs files.  If I'm not mistaken (which I might be), you actually *must* do the newline method with .sqf files, else they will not work.
Ranger

Offline Razorwings18

  • Contributing Member
  • **
  • I'm NOT a llama. I checked.
Re:if, while not working when indented
« Reply #4 on: 16 Mar 2003, 07:03:27 »
Yep... it works all right in functions. Thanks all for your help.