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

[JASS] saving data in a hashtable

Status
Not open for further replies.
Level 4
Joined
Mar 23, 2009
Messages
78
well, i have some troubles with hashtable. this code doesnt work:
JASS:
    local integer c=0
    local integer j=0
    local integer p=0
    set udg_hash=InitHashtable()
    loop
        exitwhen c>7
        loop
            exitwhen j>11
            call SaveInteger(udg_hash,c,j,c)
            set p=LoadInteger(udg_hash,c,j)
            call DisplayTextToPlayer(Player(0),0,0,I2S(p))
            //p is always equal to 0
            set j=j+1
        endloop
        set c=c+1
    endloop
what's the matter?
and another question: if i want to save abilcodes in hashtable, i should use SaveInteger or SaveHandle?
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
well, i have some troubles with hashtable. this code doesnt work:
JASS:
local integer c=0
    local integer j=0
    local integer p=0
    set udg_hash=InitHashtable()
    loop
        exitwhen c>7
        loop
            exitwhen j>11
            call SaveInteger(udg_hash,c,j,c)
            set p=LoadInteger(udg_hash,c,j)
            call DisplayTextToPlayer(Player(0),0,0,I2S(p))
            //p is always equal to 0
            set j=j+1
        endloop
        set c=c+1
    endloop
what's the matter?
and another question: if i want to save abilcodes in hashtable, i should use SaveInteger or SaveHandle?

I use saveinteger.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
JASS:
    local integer c=0
    local integer j=0
    local integer p=0
    set udg_hash=InitHashtable()
    loop
        exitwhen c>7
        loop
            exitwhen j>11
            call SaveInteger(udg_hash,c,j,c)
            set p=LoadInteger(udg_hash,c,j)
            call DisplayTextToPlayer(Player(0),0,0,I2S(p))
            //p is always equal to 0
            set j=j+1
        endloop
        set c=c+1
    endloop

i didnt test it, but i guess you want this:

JASS:
    local integer c=0
    local integer j=0
    local integer p=0
    set udg_hash=InitHashtable()
    loop
        exitwhen c>7
        set j = 0
        loop
            exitwhen j>11
            call SaveInteger(udg_hash,c,j,c)
            set p=LoadInteger(udg_hash,c,j)
            call DisplayTextToPlayer(Player(0),0,0,I2S(p))
            //p is always equal to 0
            set j=j+1
        endloop
        set c=c+1
    endloop

The variable c is global, so if you dont reset its value before the inner loop starts it will be 12 forever and the inner loop wont run at all for c > 1.
 
Level 1
Joined
Apr 24, 2009
Messages
44
I assume you want to put "set j = 0" right after "exitwhen c>7", otherwise when "c" is greater or equal than 1, j will always be 12 and the second loop will never run.

EDIT: someone's quicker :)
 
Status
Not open for further replies.
Top