• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Handle Variables Linking

Status
Not open for further replies.
Level 6
Joined
Feb 12, 2008
Messages
207
Well, as I've seen, Kattana's Handle Variables system is not working anymore, seems too old. It also seems that a good replacement for it is the Vexorian's Table3, but after surfing on lots of webpages, I've found no help or tut about using it. Im pretty new to JASS but if you could help me about this code would be really appreciated.
And It would be cool to learn to use Table3 as it looks very powerful.

This is what I was trying to do with Kattana's system:
JASS:
function HeroResurrection takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer i = GetHandleInt(t, "i")
    
    call DestroyTimerDialog( udg_Death_TimerWindow[i] )
    call ReviveHeroLoc( udg_Survivor[i], GetRectCenter(gg_rct_WarpStart), true )
    call SetUnitManaPercentBJ( udg_Survivor[i], 100 )
    set udg_Status_Hunger[i] = 100.00
    set udg_Status_Heat[i] = 100.00
    call PanCameraToTimedLocForPlayer( Player(i-1), GetRectCenter(gg_rct_WarpStart), 0 )
    if (GetLocalPlayer() == Player(i-1)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ClearSelection()
        call SelectUnit(udg_Survivor[i], true)
    endif
    
    //unleak
    set t = null
endfunction

function ReviveTimer takes nothing returns nothing
    local timer t = CreateTimer()
    local timerdialog td = CreateTimerDialog(t)
    local integer i = GetPlayerId(GetOwningPlayer(GetDyingUnit()))
    
    set udg_Death_TimerWindow[i+1] = td
    call TimerStart( t, 10, false, function HeroResurrection)
    call TimerDialogSetTitle(udg_Death_TimerWindow[i+1], GetPlayerName(Player(i)))
    call TimerDialogDisplay(udg_Death_TimerWindow[i+1], true)
    call SetHandleInt(t, "i", i+1)
    
    //unleak
    set t = null
endfunction

EDIT: Ok I'm now using Vexorian's CSData... but when the trigger executes, after the timer finishes, it crashes my Wc3. It's definitely me doing something wrong with the data retrieve... help please :B

JASS:
struct Ress
    integer i
endstruct

function HeroResurrection takes nothing returns nothing
    local Ress data = GetCSData(GetExpiredTimer())
    local timer t = GetExpiredTimer()
    local integer i = data.i
    
    call DestroyTimerDialog( udg_Death_TimerWindow[i] )
    call ReviveHeroLoc( udg_Survivor[i], GetRectCenter(gg_rct_WarpStart), true )
    call SetUnitManaPercentBJ( udg_Survivor[i], 100 )
    set udg_Status_Hunger[i] = 100.00
    set udg_Status_Heat[i] = 100.00
    call PanCameraToTimedLocForPlayer( Player(i-1), GetRectCenter(gg_rct_WarpStart), 0 )
    if (GetLocalPlayer() == Player(i-1)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ClearSelection()
        call SelectUnit(udg_Survivor[i], true)
    endif
    
    //unleak
    set t = null
    call data.destroy()
endfunction

function ReviveTimer takes nothing returns nothing
    local timer t = CreateTimer()
    local timerdialog td = CreateTimerDialog(t)
    local integer i = GetPlayerId(GetOwningPlayer(GetDyingUnit()))
    //struct data
    local Ress data = Ress.create()
    set data.i = i
    call SetCSData(t, data)
    
    set udg_Death_TimerWindow[i+1] = td
    call TimerStart( t, 10, false, function HeroResurrection)
    call TimerDialogSetTitle(udg_Death_TimerWindow[i+1], GetPlayerName(Player(i)))
    call TimerDialogDisplay(udg_Death_TimerWindow[i+1], true)
    
    //unleak
    set t = null
endfunction

//===========================================================================
function InitTrig_ReviveTimer takes nothing returns nothing
    set gg_trg_ReviveTimer = CreateTrigger(  )
    call DisableTrigger( gg_trg_ReviveTimer )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ReviveTimer, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_ReviveTimer, Condition( function Trig_ReviveTimer_Conditions ) )
    call TriggerAddAction( gg_trg_ReviveTimer, function ReviveTimer )
endfunction

EDIT2: Fixed, it was only a noob mistake, changed local integer i = GetPlayerId(GetOwningPlayer(GetDyingUnit())) with local integer i = GetPlayerId(GetOwningPlayer(GetDyingUnit()))+1 and its working now. But It would be nice to have a response about the Handle Vars as this is the 1st piece of code I make with those and had to learn it by myself so I'm pretty sure there are some tips I could have from someone with more experience.
 
Last edited:
Level 14
Joined
Nov 18, 2007
Messages
1,084
You should use TimerUtils instead of CSData since that's outdated. You'll need know vJass to use it like using structs.

Some tutorials I found helpful:
http://www.wc3campaigns.net/showthread.php?t=100953 Basically a spell made with TimerUtils.
http://www.wc3c.net/showthread.php?t=91491 Transition from handle variables to using vJass.

Other Code Stuff:

  • Inline BJ's when you can. Some BJ's don't need to be inlined like TriggerRegisterAnyUnitEventBJ since they take care of something that would be too annoying to do manually. The BJ's you should be mainly concerned about are those that just refer to native functions without doing anything else like ForGroupBJ.
  • Don't use locations unless you're using GetLocationZ. Use coordinates instead.
 
Status
Not open for further replies.
Top