Why does the hash not load?

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
For some reason it doesn't recognize when WARDROBE01 sells SHOES_ITEM and therefor SHOES_SHOP is never selected. Don't get it.

JASS:
scope ShopSystem initializer Init 

    globals 
        private constant unit WARDROBE01        = gg_unit_n00B_0032
        private constant integer SHOES_ITEM     = 'I027' 
        private constant integer SHOES_SHOP     = 'n00C'
        private hashtable hash = InitHashtable()
    endglobals
    
    private function AddShopToMain takes unit mainshop, integer dummyitem, integer newshopid returns nothing 
        local unit newshop = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), newshopid, GetUnitX(mainshop), GetUnitY(mainshop), 0)
        call SaveUnitHandle(hash, GetHandleId(mainshop), dummyitem, newshop)
        set newshop = null
    endfunction
    
    private function OnEvent takes nothing returns nothing
        local unit mainshop = GetTriggerUnit()
        local unit newshop = LoadUnitHandle(hash, GetHandleId(mainshop), GetHandleId(GetSoldItem()))
        if not (newshop == null) then 
        // its always null..?
            if GetLocalPlayer() == GetOwningPlayer(GetBuyingUnit()) then 
                call ClearSelection()
                call SelectUnit(newshop, true) 
            endif
        else
            call BJDebugMsg("Null!")
        endif   
        set mainshop = null
        set newshop = null
    endfunction

    private function Init takes nothing returns nothing 
        local trigger t = CreateTrigger()
        call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SELL_ITEM, function OnEvent)
        call AddShopToMain(WARDROBE01, SHOES_ITEM, SHOES_SHOP)
    endfunction

endscope
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
private constant unit WARDROBE01 = gg_unit_n00B_0032
You can not use preplaced unit constants during initialization inside your globals block because they actually will be initialisized after globals.
So initialisize the variable in your Init first.

I can change the Setup to this:
JASS:
private function Init takes nothing returns nothing 
        local trigger t = CreateTrigger()
        call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SELL_ITEM, function OnEvent)
        call AddShop(gg_unit_n00B_0032, SHOES_ITEM, SHOES_SHOP)
    endfunction
And it still wont load.
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
And... done.... :p

JASS:
scope ShopSystem initializer Init 

    globals 
        private constant integer RETURN         = 'I026'
        private constant integer SHOES_ITEM     = 'I027' 
        private constant integer SHOES_SHOP     = 'n00C'
        private hashtable hash = InitHashtable()
    endglobals
    
    private function AddShop takes unit mainshop, integer dummyitem, integer newshopid returns nothing 
        local unit newshop = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), newshopid, GetUnitX(mainshop), GetUnitY(mainshop), 0)
        call SaveUnitHandle(hash, GetHandleId(mainshop), dummyitem, newshop)
        call SaveUnitHandle(hash, GetHandleId(newshop), 0, mainshop)
        set newshop = null
    endfunction
    
    private function OnEvent takes nothing returns nothing
        local integer itemid = GetItemTypeId(GetSoldItem())
        local unit u = GetTriggerUnit()
        local unit newshop
        if itemid == RETURN then 
            if GetLocalPlayer() == GetOwningPlayer(GetBuyingUnit()) then 
                call ClearSelection()
                call SelectUnit(LoadUnitHandle(hash, GetHandleId(u), 0), true) 
            endif
        else 
            set newshop = LoadUnitHandle(hash, GetHandleId(u), itemid)
            if not (newshop == null) then 
                if GetLocalPlayer() == GetOwningPlayer(GetBuyingUnit()) then 
                    call ClearSelection()
                    call SelectUnit(newshop, true) 
                endif
                set newshop = null
            endif
        endif
        set u = null
    endfunction

    private function Init takes nothing returns nothing 
        local trigger t = CreateTrigger()
        call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SELL_ITEM, function OnEvent)
        call AddShop(gg_unit_n00B_0032, SHOES_ITEM, SHOES_SHOP)
    endfunction

endscope
If you are bored you may give feedback on how to improve it. Not that i'm gonna make a system out of as there is already such systems out there... That I didn't get to work ehh...
 
Status
Not open for further replies.
Top