| 03-19-2007, 04:18 AM | #1 |
I'm making a script for someone to remove bought items if the unit doesn't meet requirements. I'm using a timer, which will remove the item (since trying to remove the item in the same thread as it's acquired by a unit doesn't remove it. Anyways, here it is: JASS:globals gamecache udg_Item_Cache endglobals function Item_0zyx0_H2I takes handle h returns integer return h return 0 endfunction function Item_0zyx0_I2I takes integer i returns item return i return null endfunction function Item_RemoveItem_Child takes nothing returns nothing local timer t = GetExpiredTimer() local string attachedto = I2S(Item_0zyx0_H2I(t)) local integer itemID = GetStoredInteger(udg_Item_Cache, "ITD", attachedto) local item i = Item_0zyx0_I2I(itemID) local trigger trig = GetTriggeringTrigger() call RemoveItem(i) call DestroyTimer(t) call DestroyTrigger(trig) set t = null set i = null set trig = null endfunction function Item_RemoveItem takes item i returns nothing local timer t = CreateTimer() local integer attach = Item_0zyx0_H2I(i) local string attachedto = I2S(Item_0zyx0_H2I(t)) local trigger trig = CreateTrigger() call StoreInteger(udg_Item_Cache, "ITD", attachedto, attach) call TriggerAddAction(trig, function Item_RemoveItem_Child) call TriggerRegisterTimerExpireEvent(trig, t) call TimerStart(t, 0.5, false, null) set t = null set trig = null endfunction Now the problem rests in GetStoredInteger(udg_Item_Cache, "ITD", attachedto) where it always returns 0. For the love of me, I don't know why. The timer returns the same integer, it's using the same mission key and the gamecache is the same, but it always returns 0. Help?! Btw: I'm only creating the trigger cause I thought it was a problem with the GetExpiredTimer() on a code thats executed when a timer ends. I will change it back once I solve this problem. |
| 03-19-2007, 04:54 AM | #2 |
you can use the function event: item is sold (to unit) or something like that look in the gui functions so you dont need a timer |
| 03-19-2007, 05:27 AM | #3 |
You didn't initialize the cache. |
| 03-19-2007, 05:34 AM | #4 |
Oh jeez... that would be it! Haha, now I feel stupid... + rep |
