• 🏆 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!

Slightly different approach to H2I/H2S

Level 6
Joined
Sep 5, 2007
Messages
264
I've found a faster way of using H2I/H2S.
This only applies it there is more than 1 var stored on the specified handle.

JASS:
//**************************************
//        Local Handle Variables
//**************************************
function H2I takes handle h returns integer
    return h
    return 0
endfunction
function H2S takes handle h returns string
    return I2S(H2I(h))
endfunction

function InitLocalVars takes nothing returns nothing
    if (udg_Cache_LocalVars == null) then
        set udg_Cache_LocalVars = InitGameCache("local_vars.w3v")
    endif
endfunction

// **  Integer  **
function SetHandleVarInt takes string subject, string name, integer value returns nothing
    call StoreInteger(udg_Cache_LocalVars, subject, name, value)
endfunction
function GetHandleVarInt takes string subject, string name returns integer
    return GetStoredInteger(udg_Cache_LocalVars, subject, name)
endfunction
// **   Float   **
function SetHandleVarReal takes string subject, string name, real value returns nothing
    call StoreReal(udg_Cache_LocalVars, subject, name, value)
endfunction
function GetHandleVarReal takes string subject, string name returns real
    return GetStoredReal(udg_Cache_LocalVars, subject, name)
endfunction
// **  String   **
function SetHandleVarString takes string subject, string name, string value returns nothing
    call StoreString(udg_Cache_LocalVars, subject, name, value)
endfunction
function GetHandleVarString takes string subject, string name returns string
    return GetStoredString(udg_Cache_LocalVars, subject, name)
endfunction
// **  Boolean  **
function SetHandleVarBoolean takes string subject, string name, boolean value returns nothing
    call StoreBoolean(udg_Cache_LocalVars, subject, name, value)
endfunction
function GetHandleVarBoolean takes string subject, string name returns boolean
    return GetStoredBoolean(udg_Cache_LocalVars, subject, name)
endfunction

//-------------------
//    CONVERSIONS
//-------------------
function GetHandleVarUnit takes string subject, string name returns unit
    return GetStoredInteger(udg_Cache_LocalVars, subject, name)
    return null
endfunction
function GetHandleVarEffect takes string subject, string name returns effect
    return GetStoredInteger(udg_Cache_LocalVars, subject, name)
    return null
endfunction
function GetHandleVarTrigger takes string subject, string name returns trigger
    return GetStoredInteger(udg_Cache_LocalVars, subject, name)
    return null
endfunction
function GetHandleVarRect takes string subject, string name returns rect
    return GetStoredInteger(udg_Cache_LocalVars, subject, name)
    return null
endfunction
function GetHandleVarRegion takes string subject, string name returns region
    return GetStoredInteger(udg_Cache_LocalVars, subject, name)
    return null
endfunction
function GetHandleVarWeatherFX takes string subject, string name returns weathereffect
    return GetStoredInteger(udg_Cache_LocalVars, subject, name)
    return null
endfunction
function GetHandleVarTimer takes string subject, string name returns timer
    return GetStoredInteger(udg_Cache_LocalVars, subject, name)
    return null
endfunction
function GetHandleVarTimerDialog takes string subject, string name returns timerdialog
    return GetStoredInteger(udg_Cache_LocalVars, subject, name)
    return null
endfunction
function GetHandleVarGroup takes string subject, string name returns group
    return GetStoredInteger(udg_Cache_LocalVars, subject, name)
    return null
endfunction

function I2UNIT takes integer i returns unit
    return i
    return null
endfunction
function I2TIMER takes integer i returns timer
    return i
    return null
endfunction
function I2TIMER_DIALOG takes integer i returns timerdialog
    return i
    return null
endfunction
function I2EFFECT takes integer i returns effect
    return i
    return null
endfunction
function I2TRIGGER takes integer i returns trigger
    return i
    return null
endfunction
function I2RECT takes integer i returns rect
    return i
    return null
endfunction
function I2REGION takes integer i returns region
    return i
    return null
endfunction
function I2WEATHER_FX takes integer i returns weathereffect
    return i
    return null
endfunction
function I2GROUP takes integer i returns group
    return i
    return null
endfunction

function FlushHandleVars takes string subject returns nothing
    call FlushStoredMission(udg_Cache_LocalVars, subject)
endfunction

function FlushHandleVarReal takes string subject, string name returns nothing
    call FlushStoredReal(udg_Cache_LocalVars, subject, name)
endfunction
function FlushHandleVarInt takes string subject, string name returns nothing
    call FlushStoredInteger(udg_Cache_LocalVars, subject, name)
endfunction
function FlushHandleVarString takes string subject, string name returns nothing
    call FlushStoredString(udg_Cache_LocalVars, subject, name)
endfunction
function FlushHandleVarBoolean takes string subject, string name returns nothing
    call FlushStoredBoolean(udg_Cache_LocalVars, subject, name)
endfunction

To attach or read an attached var I use:
JASS:
    local string hand = H2S([I]unit[/I])
    local integer var1 = GetHandleVarInt(hand, "name1")
    local integer var2 = GetHandleVarInt(hand, "name2")
    local integer var3 = GetHandleVarInt(hand, "name3")
    local integer var4 = GetHandleVarInt(hand, "name4")

    <Insert other code here>

    call SetHandleVarInt(hand, "name1", var1)
    call SetHandleVarInt(hand, "name2", var2)
    call SetHandleVarInt(hand, "name3", var3)
    call SetHandleVarInt(hand, "name4", var4)

    set hand = null

Doing the H2I only once per handle is alot faster than doing it per variable.

I just thought that I'd let peoples know that I had discovered a faster & more efficient way of using it.

I know that this isn't a tutorial, but I was unable to post in the JASS section, so I posted here. Admins, feel free to move it.
 
Top