• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

game cache / hashtable / storing null

Status
Not open for further replies.
Level 17
Joined
Apr 27, 2008
Messages
2,455
I want to edit my thread, and that sounds a really silly test but i just want to be sure that trying to store null in an hashtable/gamecache doesn't flush the previous content.

JASS:
scope Test initializer init

    globals
        private gamecache Gc = InitGameCache("whatever")
        private hashtable Ht = InitHashtable()
    endglobals

    private function init takes nothing returns nothing
        local unit u = CreateUnit(Player(0),'hpea',0,0,0)
        call BJDebugMsg(I2S(GetHandleId(u)))
        call StoreUnit(Gc,"0","0",u)
        call StoreUnit(Gc,"0","0",null)
        call SaveUnitHandle(Ht,0,0,u)
        call SaveUnitHandle(Ht,0,0,null)
        set u = RestoreUnit(Gc,"0","0")
        call BJDebugMsg("gamecache : "+I2S(GetHandleId(u)))
        set u = null
        set u = LoadUnitHandle(Ht,0,0)
        call BJDebugMsg("hashtable : "+I2S(GetHandleId(u)))
    endfunction

endscope

So anyone willing to test it ?
 
neither hashtable nor gameacache overrides stored unit

Test script:
JASS:
scope s initializer i

    globals
        private gamecache gchc = null
        private hashtable htbl = null
    endglobals
    
    private function i takes nothing returns nothing
        local unit u = CreateUnit(Player(0), 'hfoo', 0, 0, 0)
        set htbl = InitHashtable()
        set gchc = InitGameCache("cpfile")
        call SaveUnitHandle(htbl, 1, 4, u)
        call SaveUnitHandle(htbl, 1, 4, null)
        call BJDebugMsg("Hashtable: " + I2S(GetHandleId(LoadUnitHandle(htbl, 1, 4))))
        call StoreUnit(gchc, "key", "key2", u)
        call StoreUnit(gchc, "key", "key2", null)
        call BJDebugMsg("Hashtable: " + I2S(GetHandleId(RestoreUnit(gchc, "key", "key2", Player(0), 0, 0, 0))))
    endfunction
    
endscope
 
And what about strings (i prefer to be sure) :

JASS:
function Test takes nothing returns nothing
local string s1 = ""
local string s2 = null

if s1 == s2 then
    call BJDebugMsg("s1 == s2")
else
    call BJDebugMsg("s1 != s2")
endif

endfunction
 
JASS:
globals
    hashtable ht = InitHashtable()
    gamecache gc = InitGameCache("ff")
endglobals

function Test takes nothing returns nothing
    local string s1 = "aaa"
    local string s2 = null
    local string s3 = ""

    call SaveStr(ht, 1, 8, s1)
    call SaveStr(ht, 1, 8, s2)
    call BJDebugMsg("s2 override test: " + LoadStr(ht, 1, 8))
    call SaveStr(ht, 1, 8, s3)
    call BJDebugMsg("s3 override test: " + LoadStr(ht, 1, 8))
    call BJDebugMsg("Now gamecache")
    call StoreString(gc, "aa", "bb", s1)
    call StoreString(gc, "aa", "bb", s2)
    call BJDebugMsg("s2 override test: " + GetStoredString(gc, "aa", "bb"))
    call StoreString(gc, "aa", "bb", s3)
    call BJDebugMsg("s3 override test: " + GetStoredString(gc, "aa", "bb"))
endfunction

Appereantly they get rewrote every time, this print for me:
s2 override test:
s3 override test:
now gamecache
s2 override test:
s3 override test:

edit: however for every other native type(tested integer, real, boolean) it will print test == null(the null == 0/false value test)
 
Hmm, i think your test is not enough, how could see the difference between null and "" ?

JASS:
globals
    hashtable ht = InitHashtable()
    gamecache gc = InitGameCache("ff")
endglobals

function Test takes nothing returns nothing
    local string s1 = "aaa"
    local string s2 = null
    local string s3 = ""

    call SaveStr(ht, 1, 8, s1)
    call SaveStr(ht, 1, 8, s2)
    call BJDebugMsg("s2 override test: ")
     if LoadStr(ht, 1, 8) == null then
        call BJDebugMsg("null")
    endif
    // not an elseif just because xD
     if LoadStr(ht, 1, 8) == "" then
        call BJDebugMsg("/""") // can't rember it the syntax is correct, well you got the idea ^^
    endif
    call SaveStr(ht, 1, 8, s3)
    call BJDebugMsg("s3 override test: ")
     if LoadStr(ht, 1, 8) == null then
        call BJDebugMsg("null")
    endif
     if LoadStr(ht, 1, 8) == "" then
        call BJDebugMsg("/""")
    endif
    call BJDebugMsg("Now gamecache")
    call StoreString(gc, "aa", "bb", s1)
    call StoreString(gc, "aa", "bb", s2)
    call BJDebugMsg("s2 override test: ")
     if GetStoredString(gc, "aa", "bb") == null then
        call BJDebugMsg("null")
    endif
     if GetStoredString(gc, "aa", "bb") == "" then
        call BJDebugMsg("/""")
    endif
    call StoreString(gc, "aa", "bb", s3)
    call BJDebugMsg("s3 override test: ")
     if GetStoredString(gc, "aa", "bb") == null then
        call BJDebugMsg("null")
    endif
     if GetStoredString(gc, "aa", "bb") == "" then
        call BJDebugMsg("/""")
    endif
endfunction
 
it print:
s2 override test:
null
s3 override test:
""
now gamecache
s2 override test:
null
s3 override test:
""

so it really most likely works in a way that "" is allocated string and null string si unallocated one(NULL pointer)

to backup my theory:
JASS:
function Test takes nothing returns nothing
    if "" == null then
        call BJDebugMsg("\"\" == null")
    endif
endfunction

wont print anything
 
If this was C I would know how lol xD
EDIT: On second thought, I still wouldn't know how lol. I just read that from a random internet tutorial on strings. ('\0' terminated strings against another one which I forgot)
 
Okay, will try that.
EDIT: jasshelper: Invalid escape sequence character. Gonna try vanilla.
EDIT2: Vanilla crashed! haha xD
 
Well, i don't feel to create an other silly thread, so let's ask there, since it's still related to gamecache anyway.
The keys are not case sensitive, using "aAAa", is just the same as "aaaa".

I vaguely remember something about slash. It was related to gamecache keys and/or StringHash.

Path for models, sounds, ... in the object editor have only one slash but you have to use a double one in scripts IIRC (or something like that)

So is using the key "a/b" the same as "a//b" (remember i don't know if i'm talking about \ or / )

Same for StringHash, does it give the same integer ?
 
"a\b" produces errors; Unexpected: " on jasshelper, a crash on vanilla.

EDIT:
So is using the key "a/b" the same as "a//b" (remember i don't know if i'm talking about \ or / )
Same for StringHash, does it give the same integer ?

Can't test it because "a\b" produces errors "Unexpected: "" and a crash on vanilla WE.

The keys are not case sensitive, using "aAAa", is just the same as "aaaa"
StringHash does indeed produce the same integer, it's case insensitive.

JASS:
library StringHashTest initializer init
    
    function SHTest takes nothing returns nothing
        local integer a=StringHash("aAAa")
        local integer b=StringHash("aaaa")
        if a==b then
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60.00,"\"aAAa\" is equal to \"aaaa\"")
        else
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60.00,"\"aAAa\" is not equal to \"aaaa\"")
        endif
    endfunction
    
    private function init takes nothing returns nothing
        call TimerStart(CreateTimer(),1.0,false,function SHTest)
    endfunction
endlibrary

library NullTest initializer init
    
    function NTest takes nothing returns nothing
        if ""=="/0" then
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60.00,"\"\" is equal to \"\\0\"")
        else
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60.00,"\"\" is not equal to \"\\0\"")
        endif
    endfunction
    

    private function init takes nothing returns nothing
        call TimerStart(CreateTimer(),1.0,false,function NTest)
    endfunction
endlibrary


attachment.php
 

Attachments

  • test_screenshot.JPG
    test_screenshot.JPG
    36.2 KB · Views: 216
  • testmap.w3m
    testmap.w3m
    12.3 KB · Views: 103
Last edited:
Status
Not open for further replies.
Back
Top