High amount of conditions

Tyman2007

Ya Rly >.
Reaction score
74
I'm not a very good Jass user if I do say so myself. I use vjass and am making a system. I want to know how to I make something like an if/then/else statement have a high amount of conditions. Over 10 actually, w/o writing 3 lines for each condition.

If at all possible..
 

BRUTAL

I'm working
Reaction score
118
JASS:
if boolean1 and boolean2 and not boolean3 then

Did you mean something like that? : s
If you meant what i think you mean, then you basically just put 'and' between conditions on the same line to add multiple conditions.
Other conditions keywords are 'or' which can be used to check if one of the conditions is true, like:
JASS:
if boolean1 or boolean2 then

And also the keyword 'not' which is just basically to check if something is false.
 

Tyman2007

Ya Rly >.
Reaction score
74
yes, but I don't want the lines to be interlaced. Something like

function conds
cond1
cond2
cond3
...
endfunction

if function cond

or something like that.
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
JASS:
if the_game == "lost" then
    call BJDebugMsg("You just lost the game")
elseif the_game == "lost" then
    call BJDebugMsg("You just lost the game")
elseif the_game == "lost" then
    call BJDebugMsg("You just lost the game")
elseif the_game == "lost" then
    call BJDebugMsg("You just lost the game")
elseif the_game == "lost" then
    call BJDebugMsg("You just lost the game")
elseif the_game == "lost" then
    call BJDebugMsg("You just lost the game")
endif


this?
 

Tyman2007

Ya Rly >.
Reaction score
74
In a sense, but something easier. Like...

func addconds
call addOrCond(something, true)
endfunc

Adds an or condition to a trigger that makes a trigger return either true or false as specified?

If one doesn't exist like that it would be a good system to have..

I don't know how it would work.. Looks like I would have to do it the hard way.
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
You can always replace your
JASS:
if ... then
endif
block with a function that returns a boolean and just return this value like that:
[ljass]return IsUnitSmexy() and IsUnitLOL()[/ljass]
However, you can not avoid this 3-liner (you'd have to set it somewhere else), you just improve readability by that at the cost of speed.

You can use elseif, however. That saves one line per condition.


You can - however - always rethink your conditions. Sometimes there is a shortcut like in the following example:
JASS:
if P == Player(1) or P == Player(2) ... or P == Player(7) then
//becomes:
if GetPlayerId(P) < 8 then


Sometimes you can also avoid some conditions by using logic, for example, if certain conditions exclude others. For example, [ljass]IsUnitType(u, UNIT_TYPE_DEAD)[/ljass] only returns true, if the unit exists AND is dead. So calling this is enough if you want to find out wether a unit is dead. If the unit doesn't exist, then the condition will return false.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top