• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] GUI and JASS

Status
Not open for further replies.
Level 6
Joined
Jun 30, 2006
Messages
230
I was curious of a few things regarding the two.
Lately I've been going through my triggers and recreating any of them that can be done in GUI. I learned triggers by jumping straight into JASS, but now I want to make them GUI if possible to allow others to easily use them and understand them as well.

Take my Clock as an example:

GUI converted to JASS:
JASS:
function Trig_Clock_Func001Func004C takes nothing returns boolean
    if ( not ( udg_f < 59 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Clock_Func001A takes nothing returns nothing
    set udg_p = GetEnumPlayer()
    set udg_f = GetPlayerState(udg_p, PLAYER_STATE_RESOURCE_FOOD_USED)
    set udg_l = GetPlayerState(udg_p, PLAYER_STATE_RESOURCE_LUMBER)
    if ( Trig_Clock_Func001Func004C() ) then
        set udg_f = ( udg_f + 1 )
        call SetPlayerStateBJ( udg_p, PLAYER_STATE_RESOURCE_FOOD_USED, udg_f )
    else
        call SetPlayerStateBJ( udg_p, PLAYER_STATE_RESOURCE_FOOD_USED, 0 )
        set udg_l = ( udg_l + 1 )
        call SetPlayerStateBJ( udg_p, PLAYER_STATE_RESOURCE_LUMBER, udg_l )
    endif
endfunction

function Trig_Clock_Actions takes nothing returns nothing
    call ForForce( GetPlayersAll(), function Trig_Clock_Func001A )
endfunction

//===========================================================================
function InitTrig_Clock takes nothing returns nothing
    set gg_trg_Clock = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Clock, 1.00 )
    call TriggerAddAction( gg_trg_Clock, function Trig_Clock_Actions )
endfunction

Created only in JASS:
JASS:
function ClockTick takes nothing returns nothing
    local player p = GetEnumPlayer()
    local integer f = GetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_USED )
    local integer l = GetPlayerState( p, PLAYER_STATE_RESOURCE_LUMBER )
    if f<59 then
        set f = f + 1
        call SetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_USED, f )
    else
        call SetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_USED, 0 )
        set l = l + 1
        call SetPlayerState( p, PLAYER_STATE_RESOURCE_LUMBER, l )
    endif
    set p = null
endfunction

function ClockActions takes nothing returns nothing
    call ForForce( bj_FORCE_ALL_PLAYERS, function ClockTick )
endfunction

//===========================================================================
function InitTrig_Clock takes nothing returns nothing
    set gg_trg_Clock = CreateTrigger()
    call TriggerRegisterTimerEvent( gg_trg_Clock, 1.00, true )
    call TriggerAddAction( gg_trg_Clock, function ClockActions )
endfunction

Aside from setting p = null (how do you do this in GUI? I can't find it...), there isn't much difference aside from getting rid of useless BJ's and such. And getting rid of the pointless return true/false function.

My Questions:
1. How do you set a variable equal to null in GUI? Or do you just have to call a custom script to do it?
2. What would be the speed difference in Gameplay? This happens every second, and there are a lot of things happening on this map anyways. Performance is key.
3. When Blizzard adds udg_ in front of a variable, doesn't that mean it is global? Can I not create local variables in GUI? The only way I know to create variables using the GUI is to click on Edit > Variables.

My GUI, for your information:
  • Clock
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set p = (Picked player)
          • Set f = (p Food used)
          • Set l = (p Current lumber)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • f Less than 59
            • Then - Actions
              • Set f = (f + 1)
              • Player - Set p Food used to f
            • Else - Actions
              • Player - Set p Food used to 0
              • Set l = (l + 1)
              • Player - Set p Current lumber to l
I've had a long break from doing this, several months, so please be patient.
Also, I wasn't entirely sure if this would go in GUI or JASS, I ask some GUI specific questions, but the code comparison is JASS, so I just guessed...
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
You must be the first one who moves on from jass to gui :)

GUI only has global variables... if you want to use locals or return a variable to null, you must use custom scripts, which technically turns GUI into "enhanced" gui. In other words: if you need locals, stick to jass. That's safest.
 
Level 7
Joined
Nov 12, 2005
Messages
299
> What would be the speed difference in Gameplay?
Well...BJ/wrapper calls tend to be around twice as slow compared to natives.
But the actual speed of these things are measured in 1/1000000 seconds so BJs should be avoided, but it's probably no big deal.

> how do you do this in GUI?
You can't without a custom script. But player locals do not need to be nulled anyway.
Units can be nulled in GUI by setting a variable to "No unit".

> Can I not create local variables in GUI?
Yes, you can. But you need to be very careful. First of all you can't do it with arrays. Second in GUI you can't see the functions so it's better to convert the trigger and make sure the local variable is only used in the function you declared it in. Overall Jass is recommended if you want locals.
 
Level 6
Joined
Jun 30, 2006
Messages
230
Grr... all my favorite triggers are going to have to be JASS...

Player(i) is just too handy in loops ;)

...Or can I still use it? I'm not familiar with GUI, but there didn't appear to be a way to do this.

And before I forget, leaving in the BJs/wrappers will decrease performance, but it's so small it's not going to really matter? It will in my spawn function because it is so huge, but has to be JASS anyways.
 
Level 6
Joined
Jun 30, 2006
Messages
230
To an extent, but they have no idea how it works. They look at it and freak out.

It's no big deal, anything important I'll just use JASS, and GUI everything else.
 
Status
Not open for further replies.
Top