OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Kurayami on 30 Sep 2003, 12:49:31
-
I'm having a problem with a script and I'm not really sure why...
#East
if (_Weapon select 0 == "AK74GrenadeLauncher") then {_Ammo1 = "AK74"} else {_Ammo1 = "AK47"}
RemoveAllWeapons _Unit
goto "Loop1"
This works absolutely fine if it's
? (_Weapon select 0 == "AK74GrenadeLauncher") : _Ammo = "AK74"I'm assuming the problem is some kind of syntax problem, but I'm not sure what. It works fine if I replace the local variable equasions with something like "hint = "blah""
Any help? Thanks.
-
"#East
if (_Weapon select 0 == "AK74GrenadeLauncher") then {_Ammo1 = "AK74"} else {_Ammo1 = "AK47"}
RemoveAllWeapons _Unit
goto "Loop1""
that certainly does not make sense.
you dont need that. i dont now why you need to to the command "else" ether. just use
? (_Weapon select 0 == "AK74GrenadeLauncher") : _Ammo = "AK74"
if the first one doesn't work, then use the secong one ;)
The "if" and "else" command only works with ofp version 1.85 :-*
hmmm, your question really doesn't make sense... or it may just be that i am tired...
my reply doesn't make sense at all... it may help tho.... but it dont make any sense at all
-
The "if" and "else" command only works with ofp version 1.85 :-*
I'm running 1.92 at the moment, so that shouldn't be the problem.
hmmm, your question really doesn't make sense... or it may just be that i am tired...
my reply doesn't make sense at all... it may help tho.... but it dont make any sense at all
Well, I wanted to use else because I planned to stack some more things into that equsion for the Ammo. I also have a couple of other things doing checks for _Ammo1 and wanted to make it a bit cleaner...
But upon reading this I realized that
A: I probably shouldn't be scripting at 5AM
and
B: I could just use two equasions and "in" and an array instead.
The reason I wanted to use else is because I didn't want to define that local variable 1000 times in the middle of the script.
Oh, well. Thanks.
Why doesn't it work, though? I'm nearly possitive it's syntax, but I tried writing it in every form that I could think of...
I don't need that working to make the script work now, but I'd like to know why it doesn't work just the same. Feel free to point out that I'm an idiot if I'm missing something basic. :P
-
The reason it doesn't work is because you don't define _Ammo1
outside the then and else's. _Ammo1 is local within the 'if' and 'else' scope
only and is not visible outside.
Try this:
_Ammo1 = ""
if (_Weapon select 0 == "AK74GrenadeLauncher") then {_Ammo1 = "AK74"} else {_Ammo1 = "AK47"}
If you are a little more adventerous, you could also try:
_Ammo1 = if (_Weapon select 0 == "AK74GrenadeLauncher") then {"AK74"} else {"AK47"}
This should do the same because if()then{}else{} returns the last expression
(in your case always "AK74").