Home   Help Search Login Register  

Author Topic: A bit of help with "else"  (Read 638 times)

0 Members and 2 Guests are viewing this topic.

Offline Kurayami

  • Members
  • *
A bit of help with "else"
« on: 30 Sep 2003, 12:49:31 »
I'm having a problem with a script and I'm not really sure why...

Code: [Select]
#East
   if (_Weapon select 0 == "AK74GrenadeLauncher") then {_Ammo1 = "AK74"} else {_Ammo1 = "AK47"}
      RemoveAllWeapons _Unit
      goto "Loop1"

This works absolutely fine if it's

Code: [Select]
? (_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.

_hammy_

  • Guest
Re:A bit of help with "else"
« Reply #1 on: 01 Oct 2003, 06:23:14 »
Code: [Select]
"#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

Code: [Select]
? (_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
« Last Edit: 01 Oct 2003, 06:24:34 by HAMMY »

Offline Kurayami

  • Members
  • *
Re:A bit of help with "else"
« Reply #2 on: 01 Oct 2003, 11:44:16 »
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.

Quote
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
« Last Edit: 01 Oct 2003, 11:45:06 by Kurayami »

Offline Spinor

  • Members
  • *
  • I'm a llama!
    • The chain of command
Re:A bit of help with "else"
« Reply #3 on: 01 Oct 2003, 17:13:21 »
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:
Code: [Select]
_Ammo1 = ""
if (_Weapon select 0 == "AK74GrenadeLauncher") then {_Ammo1 = "AK74"} else {_Ammo1 = "AK47"}

If you are a little more adventerous, you could also try:
Code: [Select]
_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").