HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Passing a unit to gamecache

07-05-2008, 12:09 PM#1
the-thingy
Is it possible to pass a unit to gamecache? I was looking at CSSafeCache yesterday, and couldn't find anything relating to attaching handles (and, more specifically, units). Can you only pass non-handle types to cache?

And yes, I do know I can use a struct, and so on, so forth, but I just want to pass a single unit, and I don't want to use a struct unless it's absolutely necessary.

So, is there any way at all (that's safe to use) of passing a unit directly to gamecache, without a struct, and retrieving it from another function?

And yes, I know there are alternatives to gamecache (which may/may not be better than GC) but (1) I want to mess around with various ways of passing data between functions, just for the hell of it, and (2)
Quote:
When you code things correctly, speed is not really that important
so please don't bring "oh, gamecache's slow" into the thread :)
07-05-2008, 12:23 PM#2
chobibo
The only way to pass a unit to gamecache is to use Blizzard's return bugs
Collapse Unit to Integer:
function H2I takes handle h returns integer
 return h
 return 0
endfunction
Collapse Integer to Unit:
function I2U takes handle h returns integer
 return 0
 return null
endfunction

But this is not advisable since there are many problems concerning Integer to Handle typecasting. Instead, use structs, which return an integer.
07-05-2008, 12:28 PM#3
the-thingy
I know that I2H is dangerous :P

So, there is no safe way to pass a unit, or any other handle for that matter, to cache without a struct?
07-05-2008, 12:37 PM#4
Anitarf
Correct. GC can only store basic types (integer, real, string).
07-05-2008, 12:37 PM#5
chobibo
I don't know of any methods. There is a StoreUnit function but it does not work like the others.
07-05-2008, 12:40 PM#6
the-thingy
Quote:
Originally Posted by Anitarf
Correct. GC can only store basic types (integer, real, handle, string).

Don't you mean boolean, not handle?

Well, thanks for the info. Time to mess around and see what I get :)
07-05-2008, 02:37 PM#7
Anitarf
Yeah, that was a typo, I'll edit it out before I confuse anyone else.
07-05-2008, 04:36 PM#8
Vexorian
Quote:
Originally Posted by chobibo
I don't know of any methods. There is a StoreUnit function but it does not work like the others.
StoreUnit stores all of a unit's data in gamecache (life, experience) so you can recreate the unit later, it is there for the only intend of saving things in hard drive for campaigns.
07-06-2008, 03:36 PM#9
chobibo
so when you call RestoreUnit() it creates an exact copy of the unit you stored? It would be good if blizzard adds handle support for gamecache.