How to convert this into efficient vJass?

Carl-Fredrik

New Member
Reaction score
51
Hi everyone :)

I've heard that in Jass/vJass you can make timers in one trigger, and I was wondering how to do this since I'm learning vJass.

I made these triggers in GUI so far:

Trigger:
  • Start Upgrade Timer
    • Events
      • Time - Elapsed game time is 0.10 seconds
    • Conditions
    • Actions
      • Countdown Timer - Create a timer window for Upgrade_Timer with title Unit Upgrade:
      • Set Upgrade_TimerWindow = (Last created timer window)
      • Countdown Timer - Start Upgrade_Timer as a Repeating timer that will expire in 300.00 seconds
      • Countdown Timer - Show Upgrade_TimerWindow
      • Custom script: set gg_trg_Start_Upgrade_Timer = null
      • Custom script: call DestroyTrigger( GetTriggeringTrigger() )


Trigger:
  • Upgrade Timer Expires
    • Events
      • Time - Upgrade_Timer expires
    • Conditions
    • Actions
      • Unit - Order Emerald of Life 0001 <gen> to research Damage Upgrade
      • Unit - Order Emerald of Life 0001 <gen> to research Tower Damage Upgrade (Good)
      • Unit - Order Fel Orc Encampment 0126 <gen> to research Damage Upgrade
      • Unit - Order Fel Orc Encampment 0126 <gen> to research Tower Damage Upgrade (Evil)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • UpgradeTimerBoolean Equal to True
        • Then - Actions
          • Unit - Order Fel Orc Encampment 0126 <gen> to research Armor Upgrade
          • Unit - Order Fel Orc Encampment 0126 <gen> to research Mana Upgrade
          • Unit - Order Emerald of Life 0001 <gen> to research Armor Upgrade
          • Unit - Order Emerald of Life 0001 <gen> to research Mana Upgrade
          • Set UpgradeTimerBoolean = False
        • Else - Actions
          • Set UpgradeTimerBoolean = True


So... how do I merge this into one trigger? :)

Thanks in advance!
+Rep will (of course) be given to helping people! :)

// Carl-Fredrik
 

Exide

I am amazingly focused right now!
Reaction score
448
I don't know anything about vJASS, but it would probably help if you converted your triggers to custom text, and posted the JASS triggers. (Then the person that wants to help you don't have to re-write the triggers by themselves.)
 

Tom Jones

N/A
Reaction score
437
JASS:
scope Upgrade initializer Init
globals
    private timer         T             = CreateTimer()
    private timerdialog   T_WINDOW      
    private boolean       UPGRADE_FIRST = false
    private real          INTERVAL      = 300.
    private unit array    UNITS
    private integer array TECH_IDS
endglobals

private function onTick takes nothing returns nothing
    local integer i = 0
    
    loop
        exitwhen UNITS<i> == null
        if UPGRADE_FIRST then
            call IssueImmediateOrderById(UNITS<i>,TECH_IDS[0])
            call IssueImmediateOrderById(UNITS<i>,TECH_IDS[1])
        else
            call IssueImmediateOrderById(UNITS<i>,TECH_IDS[2])
            call IssueImmediateOrderById(UNITS<i>,TECH_IDS[3])
        endif
        set i = i+1
    endloop
    if UPGRADE_FIRST then
        set UPGRADE_FIRST = false
    else
        call PauseTimer(T)
    endif
endfunction
    
private function Actions takes nothing returns nothing
    set T_WINDOW = CreateTimerDialog(T)
    call TimerDialogDisplay(T_WINDOW,true)
    call TimerStart(T,INTERVAL,true,function onTick)
endfunction


private function Init takes nothing returns nothing
    //Initialize the trigger.
    local trigger trig = CreateTrigger()
    
    call TriggerRegisterTimerEvent(trig,.1,false)
    call TriggerAddAction(trig,function Actions)
    
    //Initialize the arrays.
    set UNITS[0] = someunit
    set UNITS[1] = someotherunit
    //etc.
    
    set TECH_IDS[0] = something
    set TECH_IDS[1] = something
    set TECH_IDS[2] = something
    set TECH_IDS[3] = something
endfunction
endscope</i></i></i></i></i>
 

Carl-Fredrik

New Member
Reaction score
51
JASS:
scope Upgrade initializer Init
globals
    private timer         T             = CreateTimer()
    private timerdialog   T_WINDOW      
    private boolean       UPGRADE_FIRST = false
    private real          INTERVAL      = 300.
    private unit array    UNITS
    private integer array TECH_IDS
endglobals

private function onTick takes nothing returns nothing
    local integer i = 0
    
    loop
        exitwhen UNITS<i> == null
        if UPGRADE_FIRST then
            call IssueImmediateOrderById(UNITS<i>,TECH_IDS[0])
            call IssueImmediateOrderById(UNITS<i>,TECH_IDS[1])
        else
            call IssueImmediateOrderById(UNITS<i>,TECH_IDS[2])
            call IssueImmediateOrderById(UNITS<i>,TECH_IDS[3])
        endif
        set i = i+1
    endloop
    if UPGRADE_FIRST then
        set UPGRADE_FIRST = false
    else
        call PauseTimer(T)
    endif
endfunction
    
private function Actions takes nothing returns nothing
    set T_WINDOW = CreateTimerDialog(T)
    call TimerDialogDisplay(T_WINDOW,true)
    call TimerStart(T,INTERVAL,true,function onTick)
endfunction


private function Init takes nothing returns nothing
    //Initialize the trigger.
    local trigger trig = CreateTrigger()
    
    call TriggerRegisterTimerEvent(trig,.1,false)
    call TriggerAddAction(trig,function Actions)
    
    //Initialize the arrays.
    set UNITS[0] = someunit
    set UNITS[1] = someotherunit
    //etc.
    
    set TECH_IDS[0] = something
    set TECH_IDS[1] = something
    set TECH_IDS[2] = something
    set TECH_IDS[3] = something
endfunction
endscope</i></i></i></i></i>


Wow, thanks! :)

It almost works... it isn't running periodically :nuts:

Which is weird since I see that it's set to true at periodic... :S

I guess it has something to do with the "PauseTimer" action?

Edit: Fixed it by removing the PauseTimer action...
 
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