Home   Help Search Login Register  

Author Topic: conditional statements w/ more than one command  (Read 420 times)

0 Members and 2 Guests are viewing this topic.

Pravit

  • Guest
conditional statements w/ more than one command
« on: 25 Dec 2003, 04:38:15 »
Hi,
What if I want to have a conditional that does more than one command? e.g.

"_x assignascargo car" foreach units roadguard
leader group roadguard assignasdriver car
"[_x] ordergetin true" foreach units roadguard
roadguard doFollow aP

^ I want to do those commands if
?((roadguard knowsabout aP)>0)
passes.

I tried using @, but that halts the script at that particular point... because I have other commands I want executed if that condition doesn't pass. Is it possible to have bracketed commands or do I just have to write a lot of spaghetti code?

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:conditional statements w/ more than one command
« Reply #1 on: 25 Dec 2003, 09:56:58 »
Hey there, Pravit

The simplest way to link multiple commands together is to throw an ; between them.

So in this case:

?((roadguard knowsabout aP)>0): "_x assignascargo car"; foreach units roadguard; leader group roadguard assignasdriver car; "[_x] ordergetin true" foreach units roadguard; roadguard doFollow aP

It gets a bit clunky with multiple commands like that (especially in a trigger).
Another alternative is to write a dedicated script to execute those commands, but personally I prefer to use a script only if really necessary ;)

Anyway, hope that helps you out

Pravit

  • Guest
Re:conditional statements w/ more than one command
« Reply #2 on: 25 Dec 2003, 21:56:58 »
Yeah, that works! Thanks! It's too bad BIS couldn't have just let us use brackets though  ::)

By the way, I can use OR and AND, right? Or do I have to use && and so on?

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:conditional statements w/ more than one command
« Reply #3 on: 26 Dec 2003, 00:50:50 »
Brackets? You mean indenting to make things easier to read? You sort of can in scripts/functions... but to a limited extent ;)

Yeap, you can use the plain english versions (or/and/not) or their fancy symbols (||/&&/!)

Just bear in mind that you can only use those in a condition statement. A command statement (such as the one we were talking about above) will throw up an error if you try them in there. You'll need to stick with ; ...