• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece!🔗 Click here to enter!

[JASS] Hashtable in Game Cache?

Status
Not open for further replies.
Level 9
Joined
Aug 2, 2008
Messages
219
Well the answer is definitely no because the only things you can store in a gamecache are integers, reals, strings, booleans and units (there is neither a StoreGamecache nor a StoreHandle native for that). But its possible to store a hashtable inside a hashtable, though.

But why uses gamecaches when we have hashtables ? Hashtables are the improved version of the gamcache. They are only 2-times slower than arrays and unlike gamecaches they use integers as keys, so they don´t cause a string leak.
 
Also, using a global is much faster than receiving it from a gamecache (or even a hashtable, for that matter). The only real way to save a hashtable to a gamecache is probably something like this:
JASS:
scope Lulu initializer Initialization
globals
    gamecache gc = InitGameCache("myCache.w3v")
    hashtable whee = InitHashtable()    
endglobals
function Initialization takes nothing returns nothing
    call StoreInteger(gc,"Data","Hashtable",GetHandleId(whee))    
endfunction
endscope

scope WhenINeedIt
function I2Hashtable takes integer id returns hashtable
    call SaveFogStateHandle(whee,0,0,ConvertFogState(id))
    return LoadHashtableHandle(whee,0,0)
endfunction

function MeNoUseGlobalHashtable takes nothing returns nothing
    local integer id = GetStoredInteger(gc,"Data","Hashtable")
    local hashtable h = I2Hashtable(id)
    call SaveUnitHandle(h,0,0,GetTriggerUnit())
    set h = null
endfunction
endscope

But I haven't tested that (I wonder if it even works), and obviously it is impractical, lol.
 
Still, you are limited in using specific values. I can't for example store a sound, right?

Yeah, gamecaches are pretty limited. There are still ways via storing strings of them and always the H2I(I2H()) method (shown above) but it is slow, and usually only needed in rare cases. (shouldn't be needed much though since hashtables are out)

Wait, gamecache needs a global variable, too? Forget it, that's lame :p

Yeah. Either way you'll end up using a global, but nothing really wrong with that. =)
 
Status
Not open for further replies.
Top