• Meta functions returning nil unless file is changed after connection
    3 replies, posted
Hello, I've recently been having several issues when trying to access shared meta functions relating to the player. I have found by changing the file then saving it while being connected fixes the issue however, this is only temporary and I need a permanent solution. Here is what happens when I print out one of the meta functions within the place of allocation before reloading the file. [code] Inventory Module Loaded Item Module Loaded function: 0x158c4888 nil nil [/code] However, after reloading they are defined [code]Inventory Module Loaded Item Module Loaded function: 0x1ed15858 function: 0x1ed15858 function: 0x1ed15858 [/code] Here is the code causing problems sh_items.lua [code] --ITEM STUFF-- meta = FindMetaTable("Player") print("Item Module Loaded") .. function meta:PickUpItem(tItem, iAmount) local tItemOrg = table.Copy(tItem) print(tItemOrg.iItemID) if SERVER then if iAmount != nil and iAmount > 0 then for i = 1, iAmount do self:SendItemInfo(tItemOrg) return end else self:SendItemInfo(tItemOrg) end end self.inven.curItems = self.inven.curItems + 1 if self.inven.curItems > self.inven.maxItems then self.inven.curItems = self.inven.maxItems if self:SearchForStack(tItemOrg.iItemID) != true then print("Max items in inventory!") return false else return end end if self:SearchForStack(tItemOrg.iItemID) != true then table.insert(self.curItemsTab,tItemOrg) print("Added Item into list!") else self.inven.curItems = self.inven.curItems - 1 end end print(meta.PickUpItem) [/code] cl_Inventory.lua [code] local lpl = LocalPlayer() print(LocalPlayer().PickUpItem) print(lpl.PickUpItem) .. function receiveItem(len) local ItemID = net.ReadInt(8) local tRecItem = tItems.types:FindTypeByID(ItemID) print(ItemID) PrintTable(tRecItem) lpl:PickUpItem(tRecItem) end net.Receive("ItemInfo",receiveItem) [/code] and finally the error received [code] [ERROR] gamemodes/dayzripoff/gamemode/cl_inventory.lua:24: attempt to call method 'PickUpItem' (a nil value) 1. func - gamemodes/dayzripoff/gamemode/cl_inventory.lua:24 2. unknown - lua/includes/modules/net.lua:31 [/code]
Probably has to do with the ordering of which the files are initially included or loaded. if cl_Inventory.lua loads before sh_items.lua then this error will occur.
That was one of my first assumptions too; however, no matter what order I still receive this error. EDIT: It also seems I can access normal functions that don't refer to a metafunction
Try instead of lpl:PickUpItem(tRecItem) do LocalPlayer():PickUpItem(tRecItem)
Sorry, you need to Log In to post a reply to this thread.