HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Saving Structs in a hashtable?

11-21-2009, 02:32 PM#1
TGhost
Hey,

I have a fairly simple question (hopefully). I want to move on from using tons of local variables to a single struct containing these, but I'm not sure how to store these in hashtables. Are structs considered handles, and if so can I just get it's ID and store it?
I searched around alittle but couldn't seem to find any mention of this anywhere. Is it because it's not possible and if it isn't, how are structs saved for use after f.ex. a timer running out?

Thanks in advance!
11-21-2009, 02:57 PM#2
DioD
structs is simple arrays.

to save struct in hashtable you need its id, and any struct reference is simple integer that you can save to hashtable directly.

also you can typecast any integer into struct reference and vise versa.
11-21-2009, 03:20 PM#3
TGhost
and I suppose you can retrieve it's id simply by using the GetHandleId function?
EDIT: Wait, what you are saying is if I save a struct DIRECTLY into a hashtable without using a GetHandleId function, it will automatically be referenced to as an integer and saved in the HT?
11-21-2009, 05:10 PM#4
Tot
Quote:
Originally Posted by TGhost
and I suppose you can retrieve it's id simply by using the GetHandleId function?
EDIT: Wait, what you are saying is if I save a struct DIRECTLY into a hashtable without using a GetHandleId function, it will automatically be referenced to as an integer and saved in the HT?

struct == integer (a struct is only an array-index)
11-21-2009, 06:11 PM#5
TGhost
Arh, thanks alot! Structs seem natural to me after I started trying some Java as well, so it should be a natural transition. Never knew structs were just array indexes, my coding knowledge is still limited, but thanks alot for taking the time to answer my stupid question!
11-22-2009, 01:43 AM#6
DioD
there is great manual for vJass, take some time to read it.
11-22-2009, 03:53 AM#7
fX_
different struct types have different arrays and they use identical indexes.

integer(myStructInstance) isnt totally unique to myStructInstance; its only unique to the myStructInstance among structs of its type. it can be used as an 'id' only in this set. it doesnt work exactly like GetHandleId(), which returns a value/id that is totally unique to the handle/object.

(ex. both the first instance of 'struct AAA' and the first instance of 'struct BBB' will be equivalent to 1, since the index/id of both instances refer to the first 'slot' in their respective arrays (identical).)

but if a struct extends another struct, it is made part of its parent type's array (i think). so you cannot have this 'overlap' of ids *among structs that extend a parent type* (but you can still have it among different 'domains' of structs (above)).

edit: anyway, point is: it doesnt work exactly like GetHandleId() (but it may suffice in some (your) cases of use).