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

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 ?
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
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
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
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
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
it actually popped s1 != s2 for me

maybe its like s1 is real pointer, while s2's underlying type would be NULL in C++<11, nullptr >11 and (void*)0 for C
so basically s1 is null string in terms of content, but s2 is null pointer as is

This is only my thought tho
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
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)
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
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
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
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
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
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)
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
Okay, will try that.
EDIT: jasshelper: Invalid escape sequence character. Gonna try vanilla.
EDIT2: Vanilla crashed! haha xD
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
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 ?
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
"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: 146
  • testmap.w3m
    12.3 KB · Views: 46
Last edited:
Status
Not open for further replies.
Top