Home   Help Search Login Register  

Author Topic: problem with "if"  (Read 1378 times)

0 Members and 2 Guests are viewing this topic.

ido

  • Guest
problem with "if"
« on: 15 Aug 2006, 18:08:01 »
I'm creating an ending cutscene for my first mission, I want to make the camera move along the team members and make each member report his health (with a subtitle).

I wrote the following script for each unit in the squad:

Code: [Select]
_cam camsettarget unit1
_cam camsetrelpos [-1,2,0.5]
_cam camcommit 2
@camcommitted _cam

if (getDammage unit1=0) then {
TitleText ["2 ok","PLAIN DOWN"] }

else {
_inj=_inj+1
if (getDammage unit1=1) then {
TitleText ["...","PLAIN DOWN"] }

else { TitleText ["2 Injured","PLAIN DOWN"] }
}
~2

when i run the script I get error messages for the TitleText ["2 Injured","PLAIN DOWN"] command. what did I do wrong ?

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: problem with "if"
« Reply #1 on: 15 Aug 2006, 19:23:43 »
when assigning a value to a variable you use =, as in

Code: [Select]
_variable = value
when checking if a variable is equal to another value, you should use ==, as in

Code: [Select]
if (getDammage unit1==0) then {
TitleText ["2 ok","PLAIN DOWN"] }

and welcome to OFPEC! :)

ido

  • Guest
Re: problem with "if"
« Reply #2 on: 15 Aug 2006, 19:42:20 »
when assigning a value to a variable you use =, as in

Code: [Select]
_variable = value
when checking if a variable is equal to another value, you should use ==, as in

Code: [Select]
if (getDammage unit1==0) then {
TitleText ["2 ok","PLAIN DOWN"] }

and welcome to OFPEC! :)

bah correct...
my programing is alittle rusty :)

another one, if I want the subtitle shown to show a number that is stored in a variable, should it be like this?:
Code: [Select]
TitleText ["Ok, radio back to HQ that we enliminated the threat\nwe have "_inj" men down and waiting for further instructions","PLAIN DOWN"]
or should it be like in C with the % operator (%d for integer is it ?)
« Last Edit: 15 Aug 2006, 22:20:12 by Ido Rosenthal »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: problem with "if"
« Reply #3 on: 15 Aug 2006, 19:48:34 »
flashpoint's proprietary scripting language shares many similarities with other languages, but this is not one of them.

you need the format command.

thus the lines become

Code: [Select]
_message = format [{"Ok, radio back to HQ that we enliminated the threat\nwe have %1 men down and waiting for further instructions"}, _inj ]

TitleText [ _message, "PLAIN DOWN"]

you could create one line of titletext including the format command, but for simplicity (and sanity) it's better to separate them.

ido

  • Guest
Re: problem with "if"
« Reply #4 on: 15 Aug 2006, 22:26:51 »
bedges, thanx I'll give it a try

changing the "=" to "==" didn't help I still get the following errors:

'|#|}': error invalid number in expression

'else |#|{ TitleText ["3 Injured","PLAIN DOWN"] } }': Error unknown operator
(I get this one to each one of the soldiers)

'if (_inj==0) then {|#|': Error Missing )

this is my whole code:
Code: [Select]
group player setBehaviour "STEALTH"
_inj=0


_cam = "camera" camcreate [-37037.96,93060.63,-32977.34]
_cam cameraeffect ["internal", "back"]
_camera camSetTarget [-37037.96,93060.63,-32977.34]
_camera camSetPos [9340.43,10925.47,74.68]
_camera camSetFOV 0.700
_camera camcommit 0
@camcommitted _cam
~7

_cam camsettarget player
_cam camsetrelpos [1,2,0.5]
_cam camcommit 3
@camcommitted _cam
TitleText ["Ok, I think we've got'em all\nlie down and keep covering to the front","PLAIN DOWN"]
~5
TitleText ["Team! Status report","PLAIN DOWN"]
~2

_cam camsettarget unit1
_cam camsetrelpos [-1,2,0.5]
_cam camcommit 2
@camcommitted _cam

if (getDammage unit1==0) then {
TitleText ["2 ok","PLAIN DOWN"] }

else {
_inj=_inj+1
if (getDammage unit1==1) then {
TitleText ["...","PLAIN DOWN"] }

else { TitleText ["2 Injured","PLAIN DOWN"] }
}
~2

//.
//.
//.
//the last camera script is repeating for all the squad members

_cam camsettarget player
_cam camsetrelpos [-1,2,0.5]
_cam camcommit 0
@camcommitted _cam

_message = format [{"Ok, radio back to HQ that we enliminated the threat\nwe have %1 men down and waiting for further

instructions"}, _inj ]



if (_inj==0) then {
TitleText ["Ok, radio back to HQ that we enliminated the threat\nand that we are waiting for further instructions","PLAIN DOWN"]
~6
}

else {
TitleText [_message,"PLAIN DOWN"]
~6
}

TitleText [" ","PLAIN DOWN"]
~5

_cam cameraeffect ["terminate", "back"]
camdestroy _cam

exit
« Last Edit: 15 Aug 2006, 22:29:17 by Ido Rosenthal »

Offline Cheetah

  • Former Staff
  • ****
Re: problem with "if"
« Reply #5 on: 15 Aug 2006, 22:44:16 »
Make sure that the if-statement is only one line, the engine can't deal with multiple lines (I think).
Also, to make a comment in the code, you have to use the semicolon (;) and you can put your comments after it. But only on that line.

Tried this and it's working:

Code: [Select]
group player setBehaviour "STEALTH"
_inj=0


_cam = "camera" camcreate [-37037.96,93060.63,-32977.34]
_cam cameraeffect ["internal", "back"]
_camera camSetTarget [-37037.96,93060.63,-32977.34]
_camera camSetPos [9340.43,10925.47,74.68]
_camera camSetFOV 0.700
_camera camcommit 0
@camcommitted _cam
~1

_cam camsettarget player
_cam camsetrelpos [1,2,0.5]
_cam camcommit 3
@camcommitted _cam
TitleText ["Ok, I think we've got'em all\nlie down and keep covering to the front","PLAIN DOWN"]
~5
TitleText ["Team! Status report","PLAIN DOWN"]
~2

_cam camsettarget unit1
_cam camsetrelpos [-1,2,0.5]
_cam camcommit 2
@camcommitted _cam

if (getDammage unit1==0) then { TitleText ["2 ok","PLAIN DOWN"] } else { _inj=_inj+1; if (getDammage unit1==1) then {TitleText ["...","PLAIN DOWN"] } else { TitleText ["2 Injured","PLAIN DOWN"] } }
~2

;the last camera script is repeating for all the squad members

_cam camsettarget player

_cam camsetrelpos [-1,2,0.5]
_cam camcommit 0
@camcommitted _cam

_message = format [{Ok, radio back to HQ that we enliminated the threat\nwe have %1 men down and waiting for further instructions}, _inj]

if (_inj==0) then { TitleText ["Ok, radio back to HQ that we enliminated the threat\nand that we are waiting for further instructions","PLAIN DOWN"]; } else { TitleText [_message,"PLAIN DOWN"] }
~6
TitleText [" ","PLAIN DOWN"]
~5

_cam cameraeffect ["terminate", "back"]
camdestroy _cam

exit
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

ido

  • Guest
Re: problem with "if"
« Reply #6 on: 16 Aug 2006, 11:10:26 »
working !
anyone feels like testing my mission and telling me what he thinks ?

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: problem with "if"
« Reply #7 on: 16 Aug 2006, 12:02:56 »
that's why we have a missions beta testing board ;)