• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece!🔗 Click here to enter!

[JASS] Condensed if/then/else

Status
Not open for further replies.
When converting to JASS directly from GUI, I get two basic types of if/then/else functions above many triggers' actions...

One is really long format:

JASS:
function SLust2 takes nothing returns boolean
if ( not ( GetUnitAbilityLevelSwapped(GetSpellAbilityId(), GetTriggerUnit()) == 1 ) ) then
return false
endif
return true
endfunction

The other is much shorter format:

JASS:
function SLustX takes nothing returns boolean
return ( UnitHasBuffBJ(GetTriggerUnit(), 'B004') == false )
endfunction

Is there a way to make the longer condition (above) into the same format as the shorter condition (below)? +Rep even if someone answered this question before you, I want to understand this function because I use it heavily in the map.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
The second one isn't an if-statement, its a boolean expression. A function that returns a true/false value. The first one includes an if-statement.

An if-statement is:

JASS:
if (someBoolean) then
    // ...
else
    // ....
endif

If you were to combine a boolean expression with an if-statement, you would get:

JASS:
if (SLust2()) then
    // ....
else
    // ....
endif

Basically, there is only one type of if-statement and that's as I have written it. What you could do is:

JASS:
function SLust2 takes nothing returns boolean
    return not (GetUnitAbilityLevelSwapped(GetSpellAbilityId(), GetTriggerUnit()) == 1) then
endfunction
 
Status
Not open for further replies.
Top