• 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.

[JASS] Game Cache

Status
Not open for further replies.
Level 1
Joined
Oct 1, 2004
Messages
2
Well self, the game cache functions like a bigass hash table. So it's hella fast to access stuff and can easily be used as an associative array. See, Vexorian wrote these tight functions (generally called the "Handle Var API") that allow you to easily associate variables in the game cache and access them faily easily. Generally the syntax is as follows:


you use SetHandle<vartype>(handle_to_associate_to, string_describing_other_var,var_being_assiciated) to associate stuff and

GetHandle<vartype>(handle_associated_to,string_describing_other_var) to get stuff that was associated

For example a common trick is to associate stuff to a timer and have the timer call a function when it expires. This example shows a function that would go along with a dummy spell to damage a target over time. So it would go along with a trigger that calls InitTimeredDamage(udg_targetUnit, ugd_casterUnit, 35.00, 30.00)

Code:
function TimeredDamage takes nothing returns nothing

    local timer t = GetExpiredTimer()
    //Now here we get the stuff we associated with our timer
    local unit target = H2U(GetHandlHandle(t, "target")  //Since the GetHandleHandle function returns a handle we cannot directly assign that to our local unit so we convert it using the return bug 
    local unit caster = H2U(GetHandleHandle(t,"caster")
    local real damage = GetHandleReal(t,"damage")
    local real duration = GetHandleReal(t, "duration")

    set duration = duration-1
    SetHandleVars(t,"duration")
    call UnitDamageTargetBJ(caster, target, damage, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_SPELLS)
    if(duration == 0) then
        PauseTimer(t)
        FlushHandleLocals()  //This line is VERY IMPORTANT  it is what releases the memory from the vars you associated so that i can be reused
        DestroyTimer(t)
        return
    endif

endfunction

function InitTimeredDamage takes unit target, unit caster, real damage, real duration

    local timer t = CreateTimer()

    //heres where we associate the unit information with the timer
    SetHandleHandle(t, "target", target)
    SetHandleHandle(t, "caster", caster)
    SetHandleReal(t, "damage", damage)
    SetHandleReal(t, "duration", duration
    StartTimer(t, 1.00, true, function TimeredDamage)
    //AT this point this function finishes but the timer we created it still running and every time it expires it will call our "TimeredDamage" function
endfunction

Now to use this stuff you need to have the Handle API stuff and the return bug funcs up there too.

Handle Vars API: http://www.wc3sear.ch/index.php?p=JASS&ID=218&sid=9f70bf40778f87bb04d62cad112f31cb

Return Bug stuff:
Add as needed depending on what variable types you need to work with.
Generally....
function H2<first letter of type> takes handle h returns <type>
return h
return null
endfunction

So one for Handle to Unit would be
Code:
function H2U takes handle h returns unit
    return h
    return 0
endfunction

I hope I made it so you could understand. If I messed anything up someone please tell me. All I know here is from looking at other people's code and the tiny bits i could get people to tell me about the game cache.
 
Status
Not open for further replies.
Top