Home   Help Search Login Register  

Author Topic: A very messy If..Then..Else problem  (Read 1754 times)

0 Members and 1 Guest are viewing this topic.

bluehawk

  • Guest
A very messy If..Then..Else problem
« on: 15 Aug 2006, 23:10:51 »
All right I think I've gotten myself into a bit a hole here. I have a very long and hard-on-the-eyes if..then..else statement in a script that comes up with an error, but I can't even see what the error is because it goes off the side of the screen when the message appears (black block at the top of the screen).

What I'm trying to do is get a bunch of squads of WW2 Finnish soldiers to move (retreat) to a waypoint when all their friendly MG and AT-guns die and the Russians are within range. Detecting the casualties and the Russians works fine, but the following script does not. I'm using a script to do this mainly because in order for the AI to fight standing up and in proper formation I've used doStop and setUnitpos commands. (The script below does not have the neccisary doFollow to override the doStop, I'm aware of this and will add it once I get this problem sorted out). Not only that but there are two waves of attack and I want the Finns to retreat regardless of which wave is overrunning them, so I need the objectives to reflect the progress of the battle, which is why the script itself checks Russian casualties to see if the first wave has been killed off.

Code: [Select]
if ( not alive leader platoon1sqd1 and not alive leader platoon1sqd2 and not alive leader platoon1sqd3 and not alive leader platoon1sqd4 and not alive tank1 and not alive tank2)
then [{"2" ObjStatus "FAILED"},{leader Finn1 doMove getMarkerPos "finn1ret"}, {leader Finn2 doMove getMarkerPos "finn2ret"},{leader Finn3 doMove getMarkerPos "finn3ret"},{leader Finn4 doMove getMarkerPos "finn4ret"}]
else [{"1" ObjStatus "FAILED"},{leader Finn1 doMove getMarkerPos "finn1ret"}, {leader Finn2 doMove getMarkerPos "finn2ret"},{leader Finn3 doMove getMarkerPos "finn3ret"},{leader Finn4 doMove getMarkerPos "finn4ret"}]

My real question here is, can you even have multiple conditions following the If? The structure I'm using is basically If not bla and not bla and not bla and not bla then {bla,bla,bla,bla} else {bla,bla,bla,bla}

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: A very messy If..Then..Else problem
« Reply #1 on: 15 Aug 2006, 23:26:06 »
yes, but you need those conditions discreetly contained in brackets, otherwise flashpoint gets confuzzled.

Code: [Select]
if ( (not (alive leader platoon1sqd1)) and (not (alive leader platoon1sqd2)) and (not (alive leader platoon1sqd3)) and (not (alive leader platoon1sqd4)) and (not (alive tank1)) and (not (alive tank2)))
then [{"2" ObjStatus "FAILED"},{leader Finn1 doMove getMarkerPos "finn1ret"}, {leader Finn2 doMove getMarkerPos "finn2ret"},{leader Finn3 doMove getMarkerPos "finn3ret"},{leader Finn4 doMove getMarkerPos "finn4ret"}]
else [{"1" ObjStatus "FAILED"},{leader Finn1 doMove getMarkerPos "finn1ret"}, {leader Finn2 doMove getMarkerPos "finn2ret"},{leader Finn3 doMove getMarkerPos "finn3ret"},{leader Finn4 doMove getMarkerPos "finn4ret"}]

try that. also try using the shorthand ?, ! , etc.

and welcome to OFPEC! :)

Offline JasonO

  • OFPEC Patron
  • ****
  • Oh no...
    • The New Life RPG
Re: A very messy If..Then..Else problem
« Reply #2 on: 15 Aug 2006, 23:59:03 »
try that. also try using the shorthand ?, ! , etc.
If your still not sure what bedges means by that...

? is same as (but shorter) if
! is same as (but shorter) not

Check out the following for:
! http://www.ofpec.com/COMREF/numeric.html#a

And..

? http://www.ofpec.com/COMREF/index.php?action=list&letter=h#if

Another shorter way of saying 'and' is  &&
http://www.ofpec.com/COMREF/index.php?action=list&letter=a#and

Does make scripts shorter.

« Last Edit: 16 Aug 2006, 10:12:20 by JasonO »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: A very messy If..Then..Else problem
« Reply #3 on: 16 Aug 2006, 00:15:49 »
Quote
Another shorter way of saying 'and' is  %%


Correction:

Another shorter way of saying 'and' is  &&



Planck
I know a little about a lot, and a lot about a little.

bluehawk

  • Guest
Re: A very messy If..Then..Else problem
« Reply #4 on: 16 Aug 2006, 00:17:37 »
It still comes up with an error.
« Last Edit: 16 Aug 2006, 00:39:04 by bluehawk »

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: A very messy If..Then..Else problem
« Reply #5 on: 16 Aug 2006, 01:00:03 »
You should separate the statements executed inside the blocks like this:

Code: [Select]
if ( condition ) then {"2" ObjStatus "FAILED";"3" ObjStatus "FAILED";"4" ObjStatus "FAILED"}
...and so on. Also you had brackets there, don't know where you got that idea from.

Looking at your huge blocks, it could be that you also need to separate stuff in your statements with parenthesis,

like:

Code: [Select]
(leader Finn1) doMove getMarkerPos "finn1ret"
but I'm not sure of this, it could be that it works without parenthesis too, really depends on operator precedence so try that too if you still fail to get it working. Basicly, a function like doMove will want one argument to left side and one argument to right side, so if it doesn't work without the parenthesis, the problem is that it is getting more than one argument for either of the sides (possibly a wrong type of argument as a consequence, too).
« Last Edit: 16 Aug 2006, 01:05:38 by Baddo »

bluehawk

  • Guest
Re: A very messy If..Then..Else problem
« Reply #6 on: 16 Aug 2006, 01:05:31 »
I got to first solution to work after all, and to make it more visually appealing I created procedures in the script that it skips ahead to.

It now looks like :
Code: [Select]
?( (!(alive leader platoon1sqd1)) && (!(alive leader platoon1sqd2)) && (!(alive leader platoon1sqd3)) && (!(alive leader platoon1sqd4)) && (!(alive tank1)) && (!(alive tank2)))  then { goto "Obj2failed"} else { goto "Obj1failed"}

#Obj2failed
"2" ObjStatus "FAILED"
{_x DoFollow leader Finn1} Foreach units Finn1
{_x DoFollow leader Finn2} Foreach units Finn2
{_x DoFollow leader Finn3} Foreach units Finn3
{_x DoFollow leader Finn4} Foreach units Finn4

leader Finn1 doMove getMarkerPos "finn1ret"
leader Finn2 doMove getMarkerPos "finn2ret"
leader Finn3 doMove getMarkerPos "finn3ret"
leader Finn4 doMove getMarkerPos "finn4ret"
goto "End"

#Obj1failed
"1" ObjStatus "FAILED"
{_x DoFollow leader Finn1} Foreach units Finn1
{_x DoFollow leader Finn2} Foreach units Finn2
{_x DoFollow leader Finn3} Foreach units Finn3
{_x DoFollow leader Finn4} Foreach units Finn4

leader Finn1 doMove getMarkerPos "finn1ret"
leader Finn2 doMove getMarkerPos "finn2ret"
leader Finn3 doMove getMarkerPos "finn3ret"
leader Finn4 doMove getMarkerPos "finn4ret"
goto "End"

#End
exit


And it works perfectly. When the custard hits the paddlewheel they up and run to the waypoint (and safety, not that it matters to the AI).

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re: A very messy If..Then..Else problem
« Reply #7 on: 16 Aug 2006, 08:58:15 »
Take care using alive with any vehicle  They can be pretty much destroyed but not quite dead.  When testing vehicles is it more reliable to use :
not (canMove Tank1) and not (canFire Tank1)

Also a neat way of checking if a set of units are all dead is:

if ({alive _x} count arrayofunits < 1) then ...

or in your case

if ({alive leader _x} count [platoon1sqd1,platoon1sqd2,platoon1sqd3,..etc] < 1) then ....

Offline JasonO

  • OFPEC Patron
  • ****
  • Oh no...
    • The New Life RPG
Re: A very messy If..Then..Else problem
« Reply #8 on: 16 Aug 2006, 10:13:42 »
Quote
Another shorter way of saying 'and' is  %%

Correction:

Another shorter way of saying 'and' is  &&

Planck

I always do that on my new keyboard. I need to learn how to go back through my posts after finishing them.

Thanks Planck ;)

I edited my original post :)

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: A very messy If..Then..Else problem
« Reply #9 on: 16 Aug 2006, 16:58:22 »
I don't think the '?' and '!' works along with 'else' and 'then'. In a line like this:

Code: [Select]
if (something) then {commands} else {more commands}
I tried replacing 'if' with '?', and a error popped up. Once I changed back I got no error. :confused: