• Question about an error!
    6 replies, posted
[highlight]If you have no intelligent comments, keep them for yourself.[/highlight] I'll try to explain you what's my problem because my english is really bad. I coded a simple inventory system for my roleplay gamemode and when I'm testing it online, people are getting an error when they try to open the derma menu (F1). I don't get their error and it works fine for me. This is the [highlight]error[/highlight] they got: [lua]madcows_roleplay\gamemode\cl_menu.lua:158: attempt to index field 'bigbeerbottle' (a nil value)[/lua] I send the items to the client so they're supposed to see the big beer bottle (inventory.lua): [lua] // Send to client all items. local files = file.FindInLua("madcows_roleplay/gamemode/items/*.lua") for k, v in pairs(files) do AddCSLuaFile("items/" .. v) end [/lua] Items and function tables (shared.lua): [lua] MAD = {} // Main table Inventory = {} // Items table Inventory.Items = {} [/lua] This is the cl_menu.lua: [lua] /*--------------------------------------------------------- ------mmmm---mmmm-aaaaaaaa----ddddddddd----------------------------------------> mmmmmmmmmmmm aaaaaaaaa dddddddddd Name: Mad Cows Roleplay mmm mmmm mmm aaa aaa ddd ddd Author: Worshipper mmm mmm mmm aaaaaaaaaaa ddd ddd Project Start: August 10th, 2009 mmm mmm aaa aaa dddddddddd File: cl_menu.lua ---mmm--------mmm-aaa-----aaa-ddddddddd----------------------------------------> ---------------------------------------------------------*/ /*--------------------------------------------------------- Name: MAD.Menu() ---------------------------------------------------------*/ local Panel local PanelTabs local Tabs local NoClosePanel = CurTime() function MAD.Menu() if not Panel or not Panel:IsValid() then Panel = vgui.Create("DFrame") Panel:SetSize(770, 580) Panel:Center() Panel:SetVisible(true) Panel:MakePopup() Panel:SetTitle("Menu") Tabs = {MAD.BackpackTab(), MAD.ShopTab()} else Panel:SetVisible(true) end NoClosePanel = CurTime() + 0.25 function Panel:Think() if input.IsKeyDown(KEY_F1) and NoClosePanel < CurTime() then self:Close() end if (!self.Dragging) then return end local x = gui.MouseX() - self.Dragging[1] local y = gui.MouseY() - self.Dragging[2] x = math.Clamp(x, 0, ScrW() - self:GetWide()) y = math.Clamp(y, 0, ScrH() - self:GetTall()) self:SetPos(x, y) end if not PanelTabs or not PanelTabs:IsValid() then PanelTabs = vgui.Create("DPropertySheet", Panel) PanelTabs:SetPos(5, 25) PanelTabs:SetSize(760, 550) PanelTabs:AddSheet("Inventory", Tabs[1], "gui/silkicons/box", false, false) PanelTabs:AddSheet("Shop", Tabs[2], "gui/silkicons/world", false, false) end for _, panel in pairs(Tabs) do panel:Update() end function Panel:Close() Panel:SetVisible(false) end end concommand.Add("rp_menu", MAD.Menu) /*--------------------------------------------------------- Name: MAD.BackpackTab() ---------------------------------------------------------*/ function MAD.BackpackTab() local InventoryPanel = vgui.Create("DPanelList") function InventoryPanel:Update() self:Clear(true) local InventoryCat = vgui.Create("DCollapsibleCategory") InventoryCat:SetLabel("Backpack") local BackpackPanel = vgui.Create("DPanelList") BackpackPanel:SetSize(0, 130) BackpackPanel:SetSpacing(1) BackpackPanel:EnableHorizontal(true) BackpackPanel:EnableVerticalScrollbar(true) local function AddBackpackIcon(model, description, item) local Icon = vgui.Create("SpawnIcon") Icon:InvalidateLayout(true) Icon:SetModel(model) Icon:SetIconSize(64) Icon:SetToolTip(description) Icon.DoClick = function() local OptionMenu = DermaMenu() OptionMenu:AddOption("Use", function() LocalPlayer():ConCommand("rp_useitem " .. item) timer.Simple(0.1, function() self:Update() end) end) OptionMenu:AddOption("Drop", function() LocalPlayer():ConCommand("rp_dropitem " .. item) timer.Simple(0.1, function() self:Update() end) end) OptionMenu:Open() surface.PlaySound(Sound("buttons/button15.wav")) end BackpackPanel:AddItem(Icon) end for k, v in pairs(InventoryTable) do AddBackpackIcon(Inventory.Items[k].Model, "Name: " .. Inventory.Items[k].Name .. "\n" .. "Description: " .. Inventory.Items[k].Description .. "\n" .. "Amount: " .. v, k) end InventoryCat:SetContents(BackpackPanel) self:AddItem(InventoryCat) end InventoryPanel:Update() return InventoryPanel end /*--------------------------------------------------------- Name: MAD.ShopTab() ---------------------------------------------------------*/ function MAD.ShopTab() local ShopPanel = vgui.Create("DPanelList") function ShopPanel:Update() self:Clear(true) local FoodCat = vgui.Create("DCollapsibleCategory") FoodCat:SetLabel("Food") local FoodPanel = vgui.Create("DPanelList") FoodPanel:SetSize(0, 130) FoodPanel:SetSpacing(1) FoodPanel:EnableHorizontal(true) FoodPanel:EnableVerticalScrollbar(true) local function AddFoodIcon(model, description, item) local Icon = vgui.Create("SpawnIcon") Icon:InvalidateLayout(true) Icon:SetModel(model) Icon:SetIconSize(64) Icon:SetToolTip(description) Icon.DoClick = function() local OptionMenu = DermaMenu() OptionMenu:AddOption("Buy", function() LocalPlayer():ConCommand("say /buyitem " .. item) end) OptionMenu:AddOption("None", function() end) OptionMenu:Open() surface.PlaySound(Sound("buttons/button15.wav")) end FoodPanel:AddItem(Icon) end AddFoodIcon(Inventory.Items["bigbeerbottle"].Model, "Name: " .. Inventory.Items["bigbeerbottle"].Name .. "\n" .. "Description: " .. Inventory.Items["bigbeerbottle"].Description .. "\nPrice: " .. tostring(GetGlobalInt("bigbeerbottlecost")) .. DOLLAR, "bigbeerbottle") AddFoodIcon(Inventory.Items["chinesefood"].Model, "Name: " .. Inventory.Items["chinesefood"].Name .. "\n" .. "Description: " .. Inventory.Items["chinesefood"].Description .. "\nPrice: " .. tostring(GetGlobalInt("chinesefoodcost")) .. DOLLAR, "chinesefood") AddFoodIcon(Inventory.Items["gaseousdrink"].Model, "Name: " .. Inventory.Items["gaseousdrink"].Name .. "\n" .. "Description: " .. Inventory.Items["gaseousdrink"].Description .. "\nPrice: " .. tostring(GetGlobalInt("gaseousdrinkcost")) .. DOLLAR, "gaseousdrink") AddFoodIcon(Inventory.Items["melon"].Model, "Name: " .. Inventory.Items["melon"].Name .. "\n" .. "Description: " .. Inventory.Items["melon"].Description .. "\nPrice: " .. tostring(GetGlobalInt("meloncost")) .. DOLLAR, "melon") AddFoodIcon(Inventory.Items["milkbottle"].Model, "Name: " .. Inventory.Items["milkbottle"].Name .. "\n" .. "Description: " .. Inventory.Items["milkbottle"].Description .. "\nPrice: " .. tostring(GetGlobalInt("milkbottlecost")) .. DOLLAR, "milkbottle") AddFoodIcon(Inventory.Items["milkcarton"].Model, "Name: " .. Inventory.Items["milkcarton"].Name .. "\n" .. "Description: " .. Inventory.Items["milkcarton"].Description .. "\nPrice: " .. tostring(GetGlobalInt("milkcartoncost")) .. DOLLAR, "milkcarton") AddFoodIcon(Inventory.Items["orange"].Model, "Name: " .. Inventory.Items["orange"].Name .. "\n" .. "Description: " .. Inventory.Items["orange"].Description .. "\nPrice: " .. tostring(GetGlobalInt("orangecost")) .. DOLLAR, "orange") AddFoodIcon(Inventory.Items["peas"].Model, "Name: " .. Inventory.Items["peas"].Name .. "\n" .. "Description: " .. Inventory.Items["peas"].Description .. "\nPrice: " .. tostring(GetGlobalInt("peascost")) .. DOLLAR, "peas") AddFoodIcon(Inventory.Items["smallbeerbottle"].Model, "Name: " .. Inventory.Items["smallbeerbottle"].Name .. "\n" .. "Description: " .. Inventory.Items["smallbeerbottle"].Description .. "\nPrice: " .. tostring(GetGlobalInt("smallbeerbottlecost")) .. DOLLAR, "smallbeerbottle") AddFoodIcon(Inventory.Items["tomatoesoup"].Model, "Name: " .. Inventory.Items["tomatoesoup"].Name .. "\n" .. "Description: " .. Inventory.Items["tomatoesoup"].Description .. "\nPrice: " .. tostring(GetGlobalInt("tomatoesoupcost")) .. DOLLAR, "tomatoesoup") AddFoodIcon(Inventory.Items["vodka"].Model, "Name: " .. Inventory.Items["vodka"].Name .. "\n" ..
Perhaps I'm not seeing the entire code, but I don't see anywhere where you actually put things into the Inventory.Items table. If you are, then my guess is the FindInLua or AddCSLuaFile paths may not be correct. Try doing a PrintTable(Inventory.Items) and see what comes out.
I don't understand because the AddCSLuaFile is supposed to be perfect. [lua] lua_run PrintTable(Inventory.Items) > PrintTable(Inventory.Items) ... cleaningproduct: USE = function: 02867E98 Name = Cleaning Product UniqueID = cleaningproduct RemoveOnUse = true Description = Makes you feel good, but as some side effects. Model = models/props_junk/garbage_plasticbottle002a.mdl dual: USE = function: 027BC7D8 Name = 9mm Dual Beretta Elites UniqueID = dual RemoveOnUse = true Description = Illegal weapon that helps you to defend yourself. Model = models/weapons/w_pist_elite_dropped.mdl gaseousdrink: USE = function: 027DD7C0 Name = Gaseous Drink UniqueID = gaseousdrink RemoveOnUse = true Description = Satisfy your hunger. Model = models/props_junk/garbage_plasticbottle003a.mdl tomatoesoup: USE = function: 027C9EB8 Name = Tomatoe Soup UniqueID = tomatoesoup RemoveOnUse = true Description = Satisfy your hunger. Model = models/props_junk/garbage_metalcan002a.mdl poison: USE = function: 027BD288 Name = Rat Poison UniqueID = poison RemoveOnUse = true Description = Makes you feel good, but as some side effects. Model = models/props_lab/jar01a.mdl 57: USE = function: 027BEC68 Name = 5.7mm FN Five-Seven UniqueID = 57 RemoveOnUse = true Description = Illegal weapon that helps you to defend yourself. Model = models/weapons/w_pist_fiveseven.mdl water: USE = function: 027BF118 Name = Water Can UniqueID = water RemoveOnUse = true Description = Satisfy your hunger. Model = models/props_junk/PopCan01a.mdl chinesefood: USE = function: 02844C90 Name = Chinese Food UniqueID = chinesefood RemoveOnUse = true Description = Satisfy your hunger. Model = models/props_junk/garbage_takeoutcarton001a.mdl smallbeerbottle: USE = function: 027C5460 Name = Small Beer Bottle UniqueID = smallbeerbottle RemoveOnUse = true Description = Makes you feel good, but as some side effects. Model = models/props_junk/garbage_glassbottle003a.mdl orange: USE = function: 0286A7D8 Name = Orange UniqueID = orange RemoveOnUse = true Description = Satisfy your hunger. Model = models/props/cs_italy/orange.mdl bigbeerbottle: USE = function: 02866DD0 Name = Big Beer Bottle UniqueID = bigbeerbottle RemoveOnUse = true Description = Makes you feel good, but as some side effects. Model = models/props_junk/garbage_glassbottle001a.mdl vodka: USE = function: 027BF4F0 Name = Vodka UniqueID = vodka RemoveOnUse = true Description = Makes you feel good, but as some side effects. Model = models/props_junk/glassjug01.mdl deagle: USE = function: 027BF718 Name = .50 Desert Eagle UniqueID = deagle RemoveOnUse = true Description = Illegal weapon that helps you to defend yourself. Model = models/weapons/w_pist_deagle.mdl detergent: USE = function: 029812F8 Name = Detergent UniqueID = detergent RemoveOnUse = true Description = Makes you feel good, but as some side effects. Model = models/props_junk/garbage_plasticbottle001a.mdl milkbottle: USE = function: 027BAC78 Name = Milk Bottle UniqueID = milkbottle RemoveOnUse = true Description = Satisfy your hunger. Model = models/props_junk/garbage_milkcarton001a.mdl melon: USE = function: 02806E18 Name = Water Melon UniqueID = melon RemoveOnUse = true Description = Satisfy your hunger. Model = models/props_junk/watermelon01.mdl peas: USE = function: 027BDCD8 Name = Peas Can UniqueID = peas RemoveOnUse = true Description = Satisfy your hunger. Model = models/props_junk/garbage_metalcan001a.mdl p228: USE = function: 027E1990 Name = 9mm Sig-Sauer P228 UniqueID = p228 RemoveOnUse = true Description = Illegal weapon that helps you to defend yourself. Model = models/weapons/w_pist_p228.mdl glock: USE = function: 027C4038 Name = 9mm Glock 18 UniqueID = glock RemoveOnUse = true Description = Illegal weapon that helps you to defend yourself. Model = models/weapons/w_pist_glock18.mdl milkcarton: USE = function: 027D98C0 Name = Milk Carton UniqueID = milkcarton RemoveOnUse = true Description = Satisfy your hunger. Model = models/props_junk/garbage_milkcarton002a.mdl drug: USE = function: 027C7B00 Name = Marijuana UniqueID = drug RemoveOnUse = true Description = Makes you feel good, but as some side effects. Model = models/props_lab/jar01b.mdl usp: USE = function: 028E2958 Name = .45 HK USP UniqueID = usp RemoveOnUse = true Description = Illegal weapon that helps you to defend yourself. Model = models/weapons/w_pist_usp.mdl usp_match: USE = function: 02806D40 Name = 9mm HK USP Match UniqueID = usp_match RemoveOnUse = true Description = Illegal weapon that helps you to defend yourself. Model = models/weapons/w_pistol.mdl [/lua]
This is supposed to be a clientside table though, right? (lua_run_cl?)
Same shit. It's shared. [lua] ] lua_run_cl PrintTable(Inventory.Items) cleaningproduct: Name = Cleaning Product UniqueID = cleaningproduct RemoveOnUse = true Description = Makes you feel good, but as some side effects. Model = models/props_junk/garbage_plasticbottle002a.mdl dual: Name = 9mm Dual Beretta Elites UniqueID = dual RemoveOnUse = true Description = Illegal weapon that helps you to defend yourself. Model = models/weapons/w_pist_elite_dropped.mdl gaseousdrink: Name = Gaseous Drink UniqueID = gaseousdrink RemoveOnUse = true Description = Satisfy your hunger. Model = models/props_junk/garbage_plasticbottle003a.mdl tomatoesoup: Name = Tomatoe Soup UniqueID = tomatoesoup RemoveOnUse = true Description = Satisfy your hunger. Model = models/props_junk/garbage_metalcan002a.mdl poison: Name = Rat Poison UniqueID = poison RemoveOnUse = true Description = Makes you feel good, but as some side effects. Model = models/props_lab/jar01a.mdl 57: Name = 5.7mm FN Five-Seven UniqueID = 57 RemoveOnUse = true Description = Illegal weapon that helps you to defend yourself. Model = models/weapons/w_pist_fiveseven.mdl water: Name = Water Can UniqueID = water RemoveOnUse = true Description = Satisfy your hunger. Model = models/props_junk/PopCan01a.mdl chinesefood: Name = Chinese Food UniqueID = chinesefood RemoveOnUse = true Description = Satisfy your hunger. Model = models/props_junk/garbage_takeoutcarton001a.mdl smallbeerbottle: Name = Small Beer Bottle UniqueID = smallbeerbottle RemoveOnUse = true Description = Makes you feel good, but as some side effects. Model = models/props_junk/garbage_glassbottle003a.mdl orange: Name = Orange UniqueID = orange RemoveOnUse = true Description = Satisfy your hunger. Model = models/props/cs_italy/orange.mdl bigbeerbottle: Name = Big Beer Bottle UniqueID = bigbeerbottle RemoveOnUse = true Description = Makes you feel good, but as some side effects. Model = models/props_junk/garbage_glassbottle001a.mdl vodka: Name = Vodka UniqueID = vodka RemoveOnUse = true Description = Makes you feel good, but as some side effects. Model = models/props_junk/glassjug01.mdl deagle: Name = .50 Desert Eagle UniqueID = deagle RemoveOnUse = true Description = Illegal weapon that helps you to defend yourself. Model = models/weapons/w_pist_deagle.mdl detergent: Name = Detergent UniqueID = detergent RemoveOnUse = true Description = Makes you feel good, but as some side effects. Model = models/props_junk/garbage_plasticbottle001a.mdl milkbottle: Name = Milk Bottle UniqueID = milkbottle RemoveOnUse = true Description = Satisfy your hunger. Model = models/props_junk/garbage_milkcarton001a.mdl melon: Name = Water Melon UniqueID = melon RemoveOnUse = true Description = Satisfy your hunger. Model = models/props_junk/watermelon01.mdl peas: Name = Peas Can UniqueID = peas RemoveOnUse = true Description = Satisfy your hunger. Model = models/props_junk/garbage_metalcan001a.mdl p228: Name = 9mm Sig-Sauer P228 UniqueID = p228 RemoveOnUse = true Description = Illegal weapon that helps you to defend yourself. Model = models/weapons/w_pist_p228.mdl glock: Name = 9mm Glock 18 UniqueID = glock RemoveOnUse = true Description = Illegal weapon that helps you to defend yourself. Model = models/weapons/w_pist_glock18.mdl milkcarton: Name = Milk Carton UniqueID = milkcarton RemoveOnUse = true Description = Satisfy your hunger. Model = models/props_junk/garbage_milkcarton002a.mdl drug: Name = Marijuana UniqueID = drug RemoveOnUse = true Description = Makes you feel good, but as some side effects. Model = models/props_lab/jar01b.mdl usp: Name = .45 HK USP UniqueID = usp RemoveOnUse = true Description = Illegal weapon that helps you to defend yourself. Model = models/weapons/w_pist_usp.mdl usp_match: Name = 9mm HK USP Match UniqueID = usp_match RemoveOnUse = true Description = Illegal weapon that helps you to defend yourself. [/lua]
What file are all the items defined in? Shared? If it's shared, did you make sure to send it to the client as well as cl_menu?
I forgot to include all the items in shared.lua. I found the solution at 3 AM. :P [lua] // Include all items both serverside and clientside. local files = file.FindInLua("madcows_roleplay/gamemode/items/*.lua") for k, v in pairs(files) do include("items/" .. v) end [/lua]
Sorry, you need to Log In to post a reply to this thread.