• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] RemoveUnitFromStock and RemoveItemFromStock remove the wrong ID when the stock is still being refilled with 0 current stocks

Status
Not open for further replies.
Level 28
Joined
Feb 2, 2006
Messages
1,633
Hi,
in my own paged buttons system I want to refresh the stock values and use calls like these:

JASS:
call RemoveUnitFromStock(this.shop, this.id)
call AddUnitToStock(this.shop, this.id, this.currentStock, this.maxStock)
...
call RemoveItemFromStock(this.shop, this.id)
call AddItemToStock(this.shop, this.id, this.currentStock, this.maxStock)

However, this removes different unit and item types from the stocks. Is this a bug in the natives? If yes, how can I fix this? If not, what could be the issue here?

edit:
It seems to occur only when the stock is currently still being refilled and its value is 0. It would be useful to somehow retrieve this data but I guess this is not possible.
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,875
I remember needing to rebuild the entire Shop's inventory from scratch every time I made a change when using my own shop system. I wasn't worried about Stock replenish time though. Not too sure what the solution would be besides that.

Edit: Also, all Items need to be added to the shop via triggers.
 
Last edited:
Level 21
Joined
Mar 16, 2008
Messages
958
there are two types of shop units, one is more a market place that rotates items. the triggers work on marketplaces. then the 2nd type of shop is more just what i think of as a regular shop where you set it's constant item stock in the Object Editor.

What type of shop unit are you using those functions on?
 
Level 28
Joined
Feb 2, 2006
Messages
1,633
But what makes the difference? I know for marketplaces there is a trigger which automatically removes sold items/units which I can disable.

I have this other function:

JASS:
function SetPagedButtonsPage takes unit shop, integer page returns nothing
    local integer handleId = GetHandleId(shop)
    local integer currentPage = LoadInteger(h, handleId, KEY_CURRENT_PAGE)
    local integer maxPages = LoadInteger(h, handleId, KEY_MAX_PAGES)
    local integer totalCounter = LoadInteger(h, handleId, KEY_COUNTER)
    local integer countUnits = 0
    local integer countItems = 0
    local Type t = 0
    local SlotType s = 0
    local integer slotsPerPage = GetPagedButtonsSlotsPerPage(shop)
    local integer i = currentPage * slotsPerPage
    local integer count = i + IMinBJ(slotsPerPage, totalCounter - currentPage * slotsPerPage)
    loop
        exitwhen (i == count)
        set t = Type(LoadInteger(h, handleId, KEY_TYPE + i))
        if (not t.isSpacer()) then
            set s = SlotType(t)
            if (s.isUnit) then
                call RemoveUnitFromStock(shop, s.id)
            else
                call RemoveItemFromStock(shop, s.id)
            endif
        endif
        set t.shown = false
        set i = i + 1
    endloop
    call SaveInteger(h, GetHandleId(shop), KEY_CURRENT_PAGE, page)
    if (not HIDE_PAGE_BUTTONS_FOR_ONE_PAGE or maxPages > 1) then
        call SetUnitTypeSlots(shop, 2)
static if (not SHOW_PAGE_NUMBER_IN_PAGE_BUTTONS) then
        call AddUnitToStock(shop, NEXT_PAGE_ID, 1, 1)
        call AddUnitToStock(shop, PREVIOUS_PAGE_ID, 1, 1)
else
        call AddUnitToStock(shop, NEXT_PAGE_ID, page + 1, page + 1)
        call AddUnitToStock(shop, PREVIOUS_PAGE_ID, page + 1, page + 1)
endif
        set countUnits = 2
    else
        call RemoveUnitFromStock(shop, NEXT_PAGE_ID)
        call RemoveUnitFromStock(shop, PREVIOUS_PAGE_ID)
        call SetUnitTypeSlots(shop, 0)
        set countUnits = 0
    endif
    call SetItemTypeSlots(shop, 0)
    set i = page * slotsPerPage
    set count = i + IMinBJ(slotsPerPage, totalCounter - page * slotsPerPage)
    loop
        exitwhen (i == count)
        set t = Type(LoadInteger(h, handleId, KEY_TYPE + i))
        if (not t.isSpacer()) then
            set s = SlotType(t)
            if (s.isUnit) then
                set countUnits = countUnits + 1
                call SetUnitTypeSlots(shop, countUnits)
                call AddUnitToStock(shop, s.id, s.currentStock, s.maxStock)
            else
                set countItems = countItems + 1
                call SetItemTypeSlots(shop, countItems)
                call AddItemToStock(shop, s.id, s.currentStock, s.maxStock)
            endif
        endif
        set t.shown = true
        set i = i + 1
    endloop
static if (CHANGE_PAGE_UNIT_NAME) then
    call ChangeShopUnitName(shop)
endif
    call ExecuteChangedPageButtonsCallbacks(shop, currentPage)
endfunction

and I think it works fine but my timer function:

JASS:
// timerFunctionUpdateTime

...

 if (this.isUnit) then
// TODO: Removes different unit.
   call RemoveUnitFromStock(this.shop, this.id)
   call AddUnitToStock(this.shop, this.id, this.currentStock, this.maxStock)
else
   // TODO: Removes different item.
   call RemoveItemFromStock(this.shop, this.id)
   call AddItemToStock(this.shop, this.id, this.currentStock, this.maxStock)
endif

...

call TimerStart(autoUpdateStockTimer, 1.0, true, function SlotType.timerFunctionUpdateTime)
Apparently removes the wrong item or wrong unit.
I guess it might be a bug in my system with the wrong ID then because changing pages works fine.

edit:
I think I have found the bug now. When you remove an item from the stock while the stock is still delayed like for example Boots of Speed have 0 charges and it takes a few seconds to refill them and you remove them with the native, it removes a different item. You can only use the removal natives if the stock is not refilling with 0 charges I guess.

It seems that I won't be able to fake any refill delays anyway since I cannot be precise enough and I cannot retrieve the any stock information with natives since there are none.
 
Last edited:
Status
Not open for further replies.
Top