HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Simple Cache questions

10-16-2008, 09:09 PM#1
Flame_Phoenix
Hi guys, I am a newbie at cache and I rarely (or never) used it.
However, there comes the day for most of us that we our best option is to learn using it ...

However, I have a problem, can some you tell me, how I write a simple real number in cache ?? How do I access that number later ?
What is the difference between "missionkey" and "key" ? Can some one explain me how cache works ?

PS: I can't use vJASS now, please don't ask why.
PS: Yes, I am studying Katanna's ..
PS: I want to understand things so I can create them

+rep will be given if I get help =S
10-16-2008, 09:34 PM#2
moyack
Collapse Taken from common.j...:
native  InitGameCache   takes string campaignFile returns gamecache
native  SaveGameCache   takes gamecache whichCache returns boolean

native  StoreInteger    takes gamecache cache, string missionKey, string key, integer value returns nothing
native  StoreReal       takes gamecache cache, string missionKey, string key, real value returns nothing //Store a real...
native  StoreBoolean    takes gamecache cache, string missionKey, string key, boolean value returns nothing
native  StoreUnit       takes gamecache cache, string missionKey, string key, unit whichUnit returns boolean
native  StoreString     takes gamecache cache, string missionKey, string key, string value returns boolean

// Will return 0 if the specified value's data is not found in the cache
native  GetStoredInteger        takes gamecache cache, string missionKey, string key returns integer
native  GetStoredReal           takes gamecache cache, string missionKey, string key returns real //Returns the real
native  GetStoredBoolean        takes gamecache cache, string missionKey, string key returns boolean
native  GetStoredString         takes gamecache cache, string missionKey, string key returns string
native  RestoreUnit             takes gamecache cache, string missionKey, string key, player forWhichPlayer, real x, real y, real facing returns unit

// Helps to determine if the value has been stored in game cache
native  HaveStoredInteger        takes gamecache cache, string missionKey, string key returns boolean
native  HaveStoredReal           takes gamecache cache, string missionKey, string key returns boolean
native  HaveStoredBoolean        takes gamecache cache, string missionKey, string key returns boolean
native  HaveStoredUnit           takes gamecache cache, string missionKey, string key returns boolean
native  HaveStoredString         takes gamecache cache, string missionKey, string key returns boolean

// Cleans data...
native  FlushGameCache          takes gamecache cache returns nothing
native  FlushStoredMission      takes gamecache cache, string missionKey returns nothing
native  FlushStoredInteger      takes gamecache cache, string missionKey, string key returns nothing
native  FlushStoredReal         takes gamecache cache, string missionKey, string key returns nothing
native  FlushStoredBoolean      takes gamecache cache, string missionKey, string key returns nothing
native  FlushStoredUnit         takes gamecache cache, string missionKey, string key returns nothing
native  FlushStoredString       takes gamecache cache, string missionKey, string key returns nothing
10-16-2008, 11:11 PM#3
Bobo_The_Kodo
missionKey is like a folder where you store files in

you can have 2 things with the same key in different missionKeys

most commonly used for I2S( H2I( ) )
10-17-2008, 12:19 PM#4
Flame_Phoenix
Guys I notest we can save units in cache. Can we also save Items ?
To get a unit from cache we do

Collapse JASS:
function GetHandleUnit takes handle subject, string name returns unit
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

So I assume, to get an Item from cache we make:
Collapse JASS:
function GetHandleItem takes handle subject, string name returns item
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

But how do we store units and items in cache ??? Using this:
Collapse JASS:
function SetHandleInt takes handle subject, string name, integer value returns nothing
    if value==0 then
        call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreInteger(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

So, to store an Item, I call:
Collapse JASS:
call SetHandleInt(TargetItem, "ring", ??????)
10-17-2008, 03:11 PM#5
Ammorth
The idea for storing objects is to associate them with something else, or a value. Using H2I, you can get the id of an object and then associate that object with the other.

Collapse JASS:
call SetHandleInt(TargetItem, "ring", H2I(HeroUnit))

Now, if you have access to the HeroUnit and know it has a ring association, you can get the ring back with the return function.
10-17-2008, 03:22 PM#6
Anitarf
You shouldn't be "saving" units to cache, we don't do that anymore.
10-17-2008, 03:26 PM#7
moyack
Instead use a struct for that and use the always safe integer store...

Collapse JASS:
globals
    gamecache GC = InitGameCache("test.w3v")
endglobals

function H2I takes handle h returns integer
    return h
    return 0
endfunction

struct Items
    item i
    static method Set takes item i returns Item
        local Items I = Items.allocate()
        set I.i = i
        return I
    endmethod
endstruct

function StoreItem takes item i returns integer
    local Items I = Items.Set(i)
    call StoreInteger(GC, "Items", I2S(integer(I)), H2I(i))
    return integer(I)
endfunction

function GetStoredItem takes integer index returns item
    local Items I = Items( GetStoredInteger(GC, "Items", I2S(index))
    return I.i
endfunction
10-17-2008, 04:45 PM#8
the-thingy
@moyack:
Quote:
PS: I can't use vJASS now, please don't ask why.

You could try some DIY structs, store them in the cache, and hope for the best

Alternatively, fix NewGen (assuming your lack-of-vJASS is because of NewGen) :P
10-17-2008, 07:28 PM#9
Flame_Phoenix
I can't use vJASS because this system is for a campaign that follows GUI .. I already tried to convince the leader of the evil powers of the dark side of JASS, but I was not able to convince him.

Please, again, I must ask for your examples and such not to use vJASS in this thread.

Quote:
Now, if you have access to the HeroUnit and know it has a ring association, you can get the ring back with the return function.
This is a problem, I don't any any entity to associate my item with. Instead I have an Abstract Data type, which is a "bag".
My problem is that, for this approach to work using Abstract Data is the best thing I can think of.
SO, you say in other words, I can't save an item into cache and then have it back right ?

Quote:
You shouldn't be "saving" units to cache, we don't do that anymore.
I know Katanna's is old, but it is the only way I can actually make this work without using vJASS.
If you know of a better way please go ahead.
And no, am not saving units into cache, but items instead...

Any suggestions ?? =S
10-17-2008, 07:56 PM#10
Bobo_The_Kodo
there should be a SetHandleHandle function if you really wanna do it
10-17-2008, 07:57 PM#11
the-thingy
You could add the items you need to store to a unit (or number of units, depending on how many items you are carrying over), call StoreUnit, then call RestoreUnit in the next map and create new items based on what the restored hero is carrying? Not sure if StoreUnit keeps items though :\
10-17-2008, 08:18 PM#12
Flame_Phoenix
Quote:
there should be a SetHandleHandle function if you really wanna do it
I am already using an optimized version I created from that function. However, that allows me to place data into cache, my problem here is: "how do I get my stored data back ?"

Quote:
You could add the items you need to store to a unit (or number of units, depending on how many items you are carrying over), call StoreUnit, then call RestoreUnit in the next map and create new items based on what the restored hero is carrying? Not sure if StoreUnit keeps items though :\
This is not an option for an item system, I rather use globals than units =S
10-17-2008, 08:41 PM#13
the-thingy
What exactly are you trying to do? Transfer the items between maps, or just store the items in cache so you can refer back to them later, in the same map? Anyway, without vJASS, your options are pretty limited
10-17-2008, 09:43 PM#14
Flame_Phoenix
I know that without vJASS I am limited ... i don't have much choice however.

Anyway, I intend to save items in cache so I can refer to them late in the same map.
In addition, I it would be easier to pass such items from map to map.

I could just use a global array, but then I would still need to place items in cache to change map ...
10-17-2008, 10:17 PM#15
the-thingy
For passing between maps, I think you will need Store/RestoreUnit - I can't see how it'd be possible to carry the items between maps using the return bug since the item's handle index won't exist in the receiving map until the item is generated, right?

For the same map, just use globals?