HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Inventory System Problem

12-31-2006, 07:36 PM#1
Fireeye
I'm currently making a new inventory system and for some reason it won't change the pages.
I checked it three times and wasn't able to find the problem, did i oversee a small problem or does i have to rebuild the entire function?
Here's the function
Collapse JASS:
function SwitchPage takes unit u, integer TargetPage returns nothing
local integer LoopSlot = 0
local string s = I2S(H2I(u))
local integer Page = GetStoredInteger(udg_gc,"Inventory",s+"Page")
local integer ItemId
local integer ItemAmount
call StoreInteger(udg_gc,"Inventory",s+"Page",TargetPage)
loop
exitwhen LoopSlot > 6
//Getting all relevant values
set ItemId = GetItemTypeId(UnitItemInSlot(u,LoopSlot))
set ItemAmount = GetItemCharges(UnitItemInSlot(u,LoopSlot))
//Storing into the gamecache
call StoreInteger(udg_gc,"Inventory",s+"Page"+I2S(Page)+"Slot"+I2S(LoopSlot),ItemId)
call StoreInteger(udg_gc,"Inventory",s+"AmountPage"+I2S(Page)+"Slot"+I2S(LoopSlot),ItemAmount)
//Remove Item
call RemoveItem(UnitItemInSlot(u,LoopSlot))
//Get Stored Item + Charges for the target page
set ItemId = GetStoredInteger(udg_gc,"Inventory",s+"Page"+I2S(TargetPage)+"Slot"+I2S(LoopSlot))
set ItemAmount = GetStoredInteger(udg_gc,"Inventory",s+"Page"+I2S(TargetPage)+"Slot"+I2S(LoopSlot))
//Create Item and set the charges
call UnitAddItemById(u,ItemId)
call SetItemCharges(GetLastCreatedItem(), ItemAmount)
set LoopSlot = LoopSlot + 1
endloop
endfunction
12-31-2006, 09:44 PM#2
Vexorian
It all sounds as if it would be swaping the page twice, just checking the sympthons and my previous experience, not the code though
12-31-2006, 10:53 PM#3
Fireeye
well, i found why that error occours, for some reason, he always set the current page = 0 so you can not acces it later, but the target page works correctly, that's pretty odd, i stored the start page (1) in the game cache which works correctly and also attached the part of the game cache to that unit (string s) that also works well, but i really don't get it why wc3 ALWAYS get the value 0 for the current page.
I think i'll make further tests to get the exact problem causing that.
---Edit---
Got the exact place where the function fails.
Collapse JASS:
local integer Page = GetStoredInteger(udg_gc,"Inventory",s+"Page")
Anything else works perfect.
---Edit2---
Found the problem, for some reason WC3 didn't init the game cache, made the trigger new and it works.