• 🏆 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 + If-Then-Else + More Jass Questions later

Status
Not open for further replies.
Level 16
Joined
May 1, 2008
Messages
1,605
Seas =)

Jeah I remember post of this but after fail searching with search function I decide to make a new topic about this.

Yes the "If Then Else" in Jass is for me totally complicated. So if you know the answers, please explain it, that even a Jass beginner ( me ) can understand it <-- Thanks!

1)
JASS:
function Trig_Hero_Death_Jass_Func002C takes nothing returns boolean
    if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_Hero_Death_Jass_Actions takes nothing returns nothing
    if ( Trig_Hero_Death_Jass_Func002C() ) then
        call TriggerSleepAction( 5.00 )
        call RemoveUnit( GetTriggerUnit() )
    else
    endif
endfunction

//===========================================================================
function InitTrig_Hero_Death_Jass takes nothing returns nothing
    set gg_trg_Hero_Death_Jass = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Hero_Death_Jass, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_Hero_Death_Jass, function Trig_Hero_Death_Jass_Actions )
endfunction

What does this trigger do?
- If a unit ( Hero ( checked in the conditions )) dies, the unit should remove the unit after 5.00 seconds ( works in GUI/Jass )

Now my Questions:
1) At the 1st line you see "..... Trig_Hero_Death_Jass_Func002C ....". What is this "Func002C"? and can I change it?

2) I don't remember if the following is correct, but somehow I remember that this:
JASS:
        return false
    endif
    return true
endfunction
can be changed so it's faster - how this? ( I think it was that, if I'm not correct sorry ^^ )

3) Actually can you help me to change this trigger to the normal Jass ( with this "Func002C and so on"

===================== New Jass Trigger - What the hell is this? =====================

I have another trigger that I want to do in Jass. I'm a beginner so I convert normal GUI triggers to Jass that I can get some basic information the I write the trigger completely myself but I got a problem at this:

  • Unit Death
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of Hamburg 0076 <gen>) Not equal to Player 12 (Brown)
          • (Owner of Munich 0204 <gen>) Not equal to Player 12 (Brown)
          • (Owner of Berlin 0032 <gen>) Not equal to Player 12 (Brown)
          • (Owner of Vienna 0017 <gen>) Not equal to Player 11 (Dark Green)
          • (Owner of Budapest 0031 <gen>) Not equal to Player 11 (Dark Green)
          • (Owner of Prague 0029 <gen>) Not equal to Player 11 (Dark Green)
          • (Owner of Sarajevo 0030 <gen>) Not equal to Player 11 (Dark Green)
          • (Owner of East Instanbul 0010 <gen>) Not equal to Player 5 (Yellow)
          • (Owner of West Istanbul 0013 <gen>) Not equal to Player 5 (Yellow)
          • (Owner of Sofia 0019 <gen>) Not equal to Player 8 (Pink)
        • Then - Actions
          • Game - Display to (All players) the text: The allies have ach...
          • Trigger - Run Ally unally cmds <gen> (checking conditions)
          • Trigger - Turn off USA to GB <gen>
          • Trigger - Turn off Unit Death <gen>
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of Paris 0002 <gen>) Not equal to Player 4 (Purple)
          • (Owner of Algiers 0027 <gen>) Not equal to Player 4 (Purple)
          • (Owner of London 0015 <gen>) Not equal to Player 3 (Teal)
          • (Owner of Dublin 0028 <gen>) Not equal to Player 3 (Teal)
          • (Owner of Alexandria 0119 <gen>) Not equal to Player 3 (Teal)
          • (Owner of Rome 0014 <gen>) Not equal to Player 7 (Green)
          • (Owner of Brussels 0009 <gen>) Not equal to Player 2 (Blue)
          • (Owner of Moscow 0012 <gen>) Not equal to Player 1 (Red)
          • (Owner of St. Petersburg 0026 <gen>) Not equal to Player 1 (Red)
          • (Owner of Warsaw 0079 <gen>) Not equal to Player 1 (Red)
          • (Owner of Belgrade 0018 <gen>) Not equal to Player 6 (Orange)
        • Then - Actions
          • Game - Display to (All players) the text: The central powers ...
          • Trigger - Run Ally unally cmds <gen> (checking conditions)
          • Trigger - Turn off USA to GB <gen>
          • Trigger - Turn off Unit Death <gen>
        • Else - Actions
after I convert it to Jass it looks like:

JASS:
function Trig_Unit_Death_Jass_Func001C takes nothing returns boolean
    if ( not ( GetOwningPlayer(gg_unit_h01U_0076) != Player(11) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h00L_0204) != Player(11) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h00K_0032) != Player(11) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h00M_0017) != Player(10) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h01T_0031) != Player(10) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h00N_0029) != Player(10) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h00O_0030) != Player(10) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h00V_0010) != Player(4) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h011_0013) != Player(4) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h004_0019) != Player(7) ) ) then
        return false
    endif
    return true
endfunction

function Trig_Unit_Death_Jass_Func002C takes nothing returns boolean
    if ( not ( GetOwningPlayer(gg_unit_h00R_0002) != Player(3) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h010_0027) != Player(3) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h00U_0015) != Player(2) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h00P_0028) != Player(2) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h00Q_0119) != Player(2) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h00Z_0014) != Player(6) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h044_0009) != Player(1) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h00T_0012) != Player(0) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h00S_0026) != Player(0) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h01V_0079) != Player(0) ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(gg_unit_h00X_0018) != Player(5) ) ) then
        return false
    endif
    return true
endfunction

function Trig_Unit_Death_Jass_Actions takes nothing returns nothing
    if ( Trig_Unit_Death_Jass_Func001C() ) then
        call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_2605" )
        call ConditionalTriggerExecute( gg_trg_Ally_unally_cmds )
        call DisableTrigger( gg_trg_USA_to_GB )
        call DisableTrigger( gg_trg_Unit_Death )
    else
    endif
    if ( Trig_Unit_Death_Jass_Func002C() ) then
        call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_2606" )
        call ConditionalTriggerExecute( gg_trg_Ally_unally_cmds )
        call DisableTrigger( gg_trg_USA_to_GB )
        call DisableTrigger( gg_trg_Unit_Death )
    else
    endif
endfunction

//===========================================================================
function InitTrig_Unit_Death_Jass takes nothing returns nothing
    set gg_trg_Unit_Death_Jass = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Unit_Death_Jass, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_Unit_Death_Jass, function Trig_Unit_Death_Jass_Actions )
endfunction

As you see there are sooooo many If then else in the Jass - and I never will remember all this numbers and everything, so my question is:

Can I change the Jasstrigger that I have all the conditions in one part - or just make the Jasstrigger without all this "If then else" lines?

If someone have some time and could help me would be nice and please! remember to explain what you doing - it has no effect if I just copy it without understanding it =)

Thanks in advanced!
 
Level 4
Joined
Jan 27, 2010
Messages
133
GUI-converted triggers look ugly... If-then-else if very simple...

JASS:
// This code will always display "Yes"
if true then
   call BJDebugMsg("Yes")
else
   call BJDebugMsg("No")
endif


// ============

// This code will display yes if the triggering unit is a hero
if  IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO)  then
   call BJDebugMsg("Yes")
else
   call BJDebugMsg("No")
endif

I'll show you first how you can make it look like:

JASS:
function Trig_Hero_Death_Jass_Actions takes nothing returns nothing

  // If the triggering unit is a hero
  // (I've cnp:ed the IsUnitType-stuff from the GUI-converted function)
    if IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) then

        call TriggerSleepAction( 5.00 )         // Wait 5 seconds
        call RemoveUnit( GetTriggerUnit() )   // Remove triggering unit

    endif
endfunction

//===========================================================================
function InitTrig_Hero_Death_Jass takes nothing returns nothing
    set gg_trg_Hero_Death_Jass = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Hero_Death_Jass, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_Hero_Death_Jass, function Trig_Hero_Death_Jass_Actions )
endfunction

Now, for the converted script... All trigger-scripts starts at the Trig_Name_Actions-function.

Your script begins with checking the if-statement. If the if-statement is true, that is, if Trig_Hero_Death_Jass_Func002C returns true, it will run the code.

JASS:
// Trig_Hero_Death_Jass_Func002C
function Trig_Hero_Death_Jass_Func002C takes nothing returns boolean
    if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    return true
endfunction

// SCRIPT STARTS HERE
function Trig_Hero_Death_Jass_Actions takes nothing returns nothing

  // call Trig_Hero_Death_Jass_Func002C
    if ( Trig_Hero_Death_Jass_Func002C() ) then

        call TriggerSleepAction( 5.00 )
        call RemoveUnit( GetTriggerUnit() )
    else
    endif
endfunction

EDIT

You can do the same with the second one, just remove those extra functions, and put what you want between if and then. You might find the keyword: and useful.

JASS:
if GetOwningPlayer(gg_unit_h01U_0076) != Player(11) and GetOwningPlayer(gg_unit_h00L_0204) != Player(11) and [etc...] then
      call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_2605" )
      call ConditionalTriggerExecute( gg_trg_Ally_unally_cmds )
      call DisableTrigger( gg_trg_USA_to_GB )
      call DisableTrigger( gg_trg_Unit_Death )
    endif
 
Last edited:
Level 13
Joined
Mar 16, 2008
Messages
941
1) Blizzard defines new functions for conditions, this Trig_Hero_Death_Jass_Func002C has to be the same like
if ( Trig_Hero_Death_Jass_Func002C() ) then

2) Can be written as
return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO)

3) The trigger would look like this:
JASS:
function Trig_Hero_Death_Jass_Actions takes nothing returns nothing
    if (IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO)) then
        call TriggerSleepAction( 5.00 )
        call RemoveUnit( GetTriggerUnit() )
    else
    endif
endfunction

//===========================================================================
function InitTrig_Hero_Death_Jass takes nothing returns nothing
    set gg_trg_Hero_Death_Jass = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Hero_Death_Jass, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_Hero_Death_Jass, function Trig_Hero_Death_Jass_Actions )
endfunction

EDIT: *yawn* -.- to slow
 
Level 16
Joined
May 1, 2008
Messages
1,605
Seas =)

Dudes - I'm back and I have some problems

1) Jass - ForGroup -

I used a Jass action like this:
JASS:
call ForForce(udg_Team1, CustomVictoryBJ( Player(0), true, true))
- I know I use a BJ here, but if I ask JassHelper - I don't understand this stuff.
- I get an error: Cannot convert nothing to code - what is that?

2) Jass - Unit Group - Matching units

Yes that's one of my main problem. I want create a unit group and in this I want to put some units in with conditions like:
- Not magic immune
- Enemy of Player (x)
- ...

The problem is not that I don't know these conditions in Jass but how I start?

Example: I start with
JASS:
function Trig_Priest_Actions takes nothing returns nothing
    local group g = CreateGroup()
    // After set all locals

    call GroupEnumUnitsInRangeOfLoc(g, loc, 300, ...)

After this 3rd , JassHelper shows: "boolexpr filter". Now how I start there the conditions - because if I just would add
JASS:
IsUnitType(GetEnumUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false
I would get an error.
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
1) The second argument is asking for a code which is basically a function.
JASS:
function Hi takes nothing returns nothing //This should be above the action to get called.
    call CustomVictoryBJ(GetEnumPlayer(),true,true) //This is such an annoying BJ to inline that I didn't bother doing it. I posted how it looks like after this code.
endfunction

...
call ForForce(udg_Team1, function Hi)
...
JASS:
function CustomVictoryBJ takes player whichPlayer, boolean showDialog, boolean showScores returns nothing
    if AllowVictoryDefeat( PLAYER_GAME_RESULT_VICTORY ) then
        call RemovePlayer( whichPlayer, PLAYER_GAME_RESULT_VICTORY )

        if not bj_isSinglePlayer then
            call DisplayTimedTextFromPlayer(whichPlayer, 0, 0, 60, GetLocalizedString( "PLAYER_VICTORIOUS" ) )
        endif

        // UI only needs to be displayed to users.
        if (GetPlayerController(whichPlayer) == MAP_CONTROL_USER) then
            set bj_changeLevelShowScores = showScores
            if showDialog then
                call CustomVictoryDialogBJ( whichPlayer )
            else
                call CustomVictorySkipBJ( whichPlayer )
            endif
        endif
    endif
endfunction
2) Boolexpr is basically a function that returns a boolean.
JASS:
function MyFilter takes nothing returns boolean
    return IsUnitType(GetFilterUnit(),UNIT_TYPE_MAGIC_IMMUNE) and IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(SomeUnit)) //SomeUnit should be a global in order to be used here.
endfunction

...
call GroupEnumUnitsInRangeOfLoc(g, loc, 300, Condition(function MyFilter))
...
Also, I suggest using GroupEnumsUnitsInRange which uses coordinates instead of locations.
 
Status
Not open for further replies.
Top