need a bit of help understanding how this works, exactly

Sui-cookie

You can change this now in User CP.
Reaction score
49
in:
JASS:
function Trig_Untitled_Trigger_004_Func002C takes nothing returns boolean
    if ( not ( GetPlayerController(Player(0)) == MAP_CONTROL_USER ) ) then
        return false
    endif
    return true
endfunction

function Trig_Untitled_Trigger_004_Actions takes nothing returns nothing
    if ( Trig_Untitled_Trigger_004_Func002C() ) then
        call DisplayTextToForce( GetPlayersAll(), "p?" )
    else
        call DisplayTextToForce( GetPlayersAll(), "C?" )
    endif
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_004 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_004 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Untitled_Trigger_004, function Trig_Untitled_Trigger_004_Actions )
endfunction


It splits the possibilities by the boolean returned in
"Trig_Untitled_Trigger_004_Func002C"
but in the next function, it uses the if:
JASS:
    if ( Trig_Untitled_Trigger_004_Func002C() ) then


i don't quite understand that line... how is it determining which return it came up with? :confused:
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
First, remember that converted GUI is often poorly-constructed as far as code is concerned.

It works because the function "Trig_Untitled_Trigger_004_Func002C" returns a boolean, meaning that the result of that function is a boolean, ie. you can think of that function as if it is a boolean value that changes based on its calculation. To say "if Trig_Untitled_Trigger_004_Func002C() then" means to do the first part of the "if" when that function returns true (which is when Player(0) is a user).

When writing it yourself, having a separate function is typically unnecessary for if-then statements. You could rewrite it like this:

JASS:
function Trig_Untitled_Trigger_004_Actions takes nothing returns nothing
    if GetPlayerController(Player(0)) == MAP_CONTROL_USER then
        call DisplayTextToForce( GetPlayersAll(), "p?" )
    else
        call DisplayTextToForce( GetPlayersAll(), "C?" )
    endif
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_004 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_004 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Untitled_Trigger_004, function Trig_Untitled_Trigger_004_Actions )
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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