Or/and functions

XeRo13g

New Member
Reaction score
3
JASS:
if udg_Boolean[1]==true and (udg_Int[2]==26 or udg_Int[2]==27 or udg_udg_Int[2]==28 or udg_udg_Int[2]==29 or udg_udg_Int[2]==31) then
    do something
    endif


Issue 1: Can boolean be used with integers in the same -IF- line? (I've tested it and it seems to work as far as I understand, yet there is a warning about comparing variables with different primitive types)

Issue 2: or/and functions are supposed to leak since they return a Boolexpr. (I think Blizzard claims that Boolexpr are now fixed with the latest patch). Does someone has knowledge on this?

Should I stop using that kind of -if- formats and go with something like this?
JASS:
function Trig_Untitled_Trigger_001_Func001Func002C takes nothing returns boolean
    if ( ( udg_Int[2]== 26 ) ) then
        return true
    endif
    if ( ( udg_Int[2] == 27 ) ) then
        return true
    endif
    if ( ( udg_Int[2] == 28 ) ) then
        return true
    endif
    if ( ( udg_Int[2] == 29 ) ) then
        return true
    endif
    if ( ( udg_Int[2]== 31 ) ) then
        return true
    endif
    return false
endfunction

function Trig_Untitled_Trigger_001_Func001C takes nothing returns boolean
    if ( not ( udg_Boolean[1] == true ) ) then
        return false
    endif
    if ( not Trig_Untitled_Trigger_001_Func001Func002C() ) then
        return false
    endif
    return true
endfunction

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    if ( Trig_Untitled_Trigger_001_Func001C() ) then
    else
    endif
endfunction

Which looks terrible:(
 

Dirac

22710180
Reaction score
147
Issue 1: yes you can, as long as it returns boolean
Issue 2: [ljass]Or()[/ljass] and [ljass]And()[/ljass] do cause issues because they have to be destroyed, and the boolexpr destroy native is broken.

as for your code it would be a lot easier just to go like this
[ljass]if (udg_Int[2]>=26 and udg_Int[2]<=31) then[/ljass]
 

XeRo13g

New Member
Reaction score
3
Issue 1: yes you can, as long as it returns boolean
You mean the function to return boolean?
I've been using that kind of code in the body of the main trigger where if takes nothing and returns nothing...
 

Dirac

22710180
Reaction score
147
If anything returns boolean

[ljass]func() -> true[/ljass]
[ljass]var -> true[/ljass]
[ljass]1==1 -> true[/ljass]
 

XeRo13g

New Member
Reaction score
3
If "and/or" still cause issues, how should I go about?

The second code snippet is just how the editor converts into text and can get seriously messy when you use a lot of conditions.

PS. if (udg_Int[2]>=26 and udg_Int[2]<=31) then
Cannot but used because in this case udg_Int[2]!=30
...and it still uses "and" :(
 

Bribe

vJass errors are legion
Reaction score
67
The and/or/not keywords do not cause issues at all. The issue that he mentioned is with three completely different things: And, Or and Not, same words but instead of keywords they are functions that take code arguments.

For that, you'd use [ljass]And(function ConditionFunc1, function ConditionFunc2)[/ljass], but what you are referring to here is just [ljass]condition1 and condition2[/ljass]
 

Dirac

22710180
Reaction score
147
that [ljass]and[/ljass] causes no issues, it's very different from the native [ljass]And()[/ljass] which returns boolexpr, same thing with [ljass]or[/ljass]. I think that clears a lot of your doubts.

[ljass]if udg_Int[2]>=26 and udg_Int[2]<=31 and udg_Int[2]!=30 then[/ljass]
 

XeRo13g

New Member
Reaction score
3
JASS:
if udg_Boolean[1]==true and (udg_Int[2]==26 or udg_Int[2]==27 or udg_udg_Int[2]==28 or udg_udg_Int[2]==29 or udg_udg_Int[2]==31) then
    do something
    endif


So, since this is using the keywords, there is no need to change anything... (Let alone slightly improving the code as Dirac indicated)... I can use as many or/and as I like without leaks, yes?
 

Bribe

vJass errors are legion
Reaction score
67
Absolutely, you got nothing to fear ;)

Just a little misunderstanding you had was all. It happens.
 
General chit-chat
Help Users

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top