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

Workaround for hashtable crashes ?

Status
Not open for further replies.
Level 2
Joined
Sep 29, 2007
Messages
13
Hello,

I m trying to use hashtables as 2D arrays so that I don't need masses of arrays for all players. In my map every player has several barracks that produce units and I want to associate every barracks with an index. (So that i can do stuff like "make a hashtable with unitgroups for every barracks, insert all units produced by that rax in the group ...")

My first idea was to create a hashtable on init and put all barracks in there, but when I upgrade one I cant find it any more. :(
Second idea was to make a region around the position of every barracks and save those, so I only have to check if the producing building is in region 1, 2 ... etc. But I cant do that as well due to the worldeditor crashing.

Is there a workaround for this ? e.g. some Jass code for saving regions/rectangles or sth in my table ?

Thanks in advance,
Leartes

EDIT: I solved my inital problem of recognising the barracks, still I d like to know if there is some custom script code to save/load regions in hashtables
 
Last edited:
Level 11
Joined
Aug 25, 2006
Messages
971
Actually 2d arrays are totally possible to do with just a minor jass function.
Basically the function takes the first index, the second index, and the highest the second index can get. Make sure you don't make the 2d table too big. Arrays have a maximum index around 4000. (4096 I believe)
JASS:
function GetIndex takes integer x, integer y, integer maxy returns integer
    return x+y*maxy
endfunction
function dostuff takes nothing returns nothing
    local integer array test
    set test[GetIndex(0,0,2)] = 1
    set test[GetIndex(0,1,2)] = 2
    set test[GetIndex(1,0,2)] = 1
    set test[GetIndex(1,1,2)] = 2
endfunction
 
Level 19
Joined
Feb 4, 2009
Messages
1,313
Arrays have a maximum index around 4000. (4096 I believe)
8192 (2^13) but someone said that the last two slots would behave weird in certain circumstances so 8190 should be saver

I do not understand why you want hashtables instead of arrays, because arrays are faster than hashtables, but ok...

because hashtables have no (or a really big) size limit
so you can use "GetHandleId" which returns an integer (mostly a very big number) and asoziate it with an hashtable slot
this wouldn't work with arrays except you are using a workaround which would make things slower
 
Status
Not open for further replies.
Top