Dr_Cox1911 Posted October 28, 2016 Share Posted October 28, 2016 Hi all, I´m currently working on my shop mod and switched from buttons to a listbox to handle a variable amount of items. Pretty much all is working but I can´t figure out how to maintain the "self"-reference when using the "onmousedown"-function-pass. Here is a snipped: function ISCoxisShopWeaponUpWindow:checkPrice(_target, _onmousedown) local splitstring = luautils.split(_target, "|"); print(splitstring[2]); print(tostring(self.char:getModData().playerMoney)); end function ISCoxisShopWeaponUpWindow:create() local y = 90; local label = ISLabel:new(16, y, 20, getText('UI_CoxisShop_Weapons'), 1, 1, 1, 0.8, UIFont.Small, true); self:addChild(label); local rect = ISRect:new(16, y + 20, 390, 1, 0.6, 0.6, 0.6, 0.6); self:addChild(rect); self.CoxisShopList = ISScrollingListBox:new(16, y + 30, 390, 200, self.char, self.playerId); self.CoxisShopList:initialise() self.CoxisShopList:instantiate() self.CoxisShopList.itemheight = 22 self.CoxisShopList.onmousedown = self.checkPrice;--self.reloadButtons; self.CoxisShopList.font = UIFont.NewSmall self.CoxisShopList.drawBorder = true self:addChild(self.CoxisShopList) for itemType,value in pairs(self.items) do local item = ScriptManager.instance:getItem(itemType) self.CoxisShopList:addItem(item:getDisplayName() .. " (" .. tostring(value) .. ")", tostring(itemType) .. "|" .. tostring(value)); end self.CoxisShopBuyButton = self:createButton(290, y-15, self.onBuyMouseDown, self.char, self.playerId); end Error is thrown at "print(tostring(self.char:getModData().playerMoney));" because I´m accessing a non-table (self is nil). Link to comment Share on other sites More sharing options...
Dr_Cox1911 Posted October 29, 2016 Author Share Posted October 29, 2016 Fixed the problem by redefining the onMouseDown function from ISScrollListBox. So I´ve got a function in my script now that looks like this: function ISCoxisShopList:onMouseDown(x, y) if #self.items == 0 then return end local row = self:rowAt(x, y) if row > #self.items then row = #self.items; end if row < 1 then row = 1; end -- RJ: If you select the same item it unselect it --if self.selected == y then --if self.selected == y then --self.selected = -1; --return; --end self.selected = row; if self.onmousedown then self.onmousedown(self.target, self.items[self.selected].item, self); end end Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now