• bad argument #1 to 'pairs' (table expected, got nil)
    7 replies, posted
  • Avatar of JohnsonBrown
  • Good afternoon, I keep getting the error, "bad argument #1 to 'pairs' (table expected, got nil)" First line is the error line :( [lua] for k, v in pairs( MaskTable ) do if !table.HasValue( cl.Masks, k ) then local Dummy = { [k] = { v[1], v[2], v[3], v[4] } } table.Merge( NotPurchased, Dummy ) else local Dummy = { [k] = { v[1], v[2], v[3], v[4] } } table.Merge( HasPurchased, Dummy ) end [/lua] The code has something to do with a shop, and I am stumped here. It's very late my time, and I'd love some help. Thanks in advance guys.
  • Avatar of JohnsonBrown
  • Yes, MaskTable is indeed a table. In another lua file, called store.lua, it's the table that contains all of the items available on the shop. This lua file should be including "store.lua" but I don't think it is. [lua] include( 'autorun/store.lua' ) [/lua] This is at the top of the current lua file, the one I get the error with. From the looks of the "table expected, got nil" error, it looks like it's not linked with store.lua, otherwise it would work. This lua file is located in autorun/client if anyone is wondering.
  • Avatar of TheTrueAndy
  • If nothing works, you can do a workaround: Index the table with the shop (or some entity dunno), then call the shop's table from your current lua file. Shop.MaskTable = { }
  • Avatar of Aide
  • Try, for k, v in pairs(Store.MaskTable) do Assuming this is an older version of my store I sold to some people. Other wise give us a copy of the store.lua
  • Avatar of JohnsonBrown
  • Thanks for helping! I tried this but it still resulted in the same error :( [lua] for k, v in pairs(Store.MaskTable) do if !table.HasValue( cl.Masks, k ) then local Dummy = { [k] = { v[1], v[2], v[3], v[4] } } table.Merge( NotPurchased, Dummy ) else local Dummy = { [k] = { v[1], v[2], v[3], v[4] } } table.Merge( HasPurchased, Dummy ) end end [/lua] Here is the store.lua store.lua [lua] Chiefeh's Mask Shop was created by Chief Tiger for Chiefeh's Servers. MaskTable = { -- Name Material Price Tooltip ["majoras"] = {"Majora's Mask", "masks/majorasmask", 75, "From the famous Zelda game."}, ["coolface"] = {"Cool Face", "masks/coolface", 100, "Just put on your cool face."}, ["fuuu"] = {"FUUU- Face", "masks/fuuu", 100, "FUUUUUUUUUUUUUUUUUUUUU-"}, ["cat"] = {"Cat Face", "masks/ecg_cat", 50, "Meow bitch."}, ["ironman"] = {"Iron Man", "masks/ecg_ironman", 200, "I prefer the weapon you\nonly have to fire once."}, ["rickastley"] = {"Rick Astley", "masks/ecg_rickastley", 75, "Never gonna give you up."}, ["vegeta"] = {"Vegeta", "masks/ecg_vegeta", 100, "It's OVER 9000!!!!"}, ["boxxy"] = {"Boxxy", "masks/ecg_boxxy", 100, "Hai, mah name is boxxeh..."}, ["wolf"] = {"Wolf", "masks/ecg_wolf", 50, "PAIN is temporary.\nGLORY is eternal."}, ["lopez"] = {"George Lopez", "masks/ecg_lopez", 300, "Chihuapa!"}, ["palin"] = {"Sarah Palin", "masks/ecg_palin", 125, "Oh, good, thank you, yes."}, ["panda"] = {"Harrasment Panda", "masks/ecg_panda", 150, "One panda may not make sexual\ncommments about another panda."}, ["mudkip"] = {"Mudkip", "masks/ecg_mudkip", 75, "So i herd u liek mudkipz?"}, ["obama"] = {"Barack Obama", "masks/ecg_obama", 125, "Uh... uh, uh, uh... uh."}, ["kenny"] = {"Kenny", "masks/ecg_kenny", 150, "Ferr ferr merr ferr merr."}, ["cartman"] = {"Cartman", "masks/ecg_cartman", 150, "No kitteh, it's MY pot pie!"}, ["peter"] = {"Peter Griffin", "masks/ecg_peter", 150, "Hehehehe... diarrhea."}, ["mrt"] = {"Mr. T", "masks/ecg_mrt", 200, "Mr. T pity the fool."}, ["doug"] = {"FPS Doug", "masks/ecg_doug", 200, "BOOOM HEADSHOT!!!"}, ["starfox"] = {"Star Fox", "masks/ecg_starfox", 150, "Do a barrel roll!"}, ["bush"] = {"George W. Bush", "masks/ecg_bush", 125, "You can call me dubya."}, ["cats"] = {"Cats", "masks/ecg_cats", 100, "All your base are belong to us."}, ["billnye"] = {"Bill Nye", "masks/ecg_billnye" , 200, "Bill Nye, the science guy."}, ["cosby"] = {"Bill Cosby", "masks/ecg_cosby", 300, "Coo coo catchoo!"}, ["spongebob"] = {"Spongebob", "masks/ecg_spongebob", 150, "I\'m ready! I\'m ready! I\'m ready!"}, ["gordon"] = {"Gordon Freeman", "masks/ecg_gordon", 100, "....................."}, ["lazor"] = {"Lazor", "masks/ecg_shoop", 150, "I\'MA FIRIN MAH LAZOR!"}, ["quagmire"] = {"Glenn Quagmire", "masks/ecg_quagmire", 150, "Giggity giggity goo!"}, ["smiley"] = {"Awesome Smiley", "masks/ecg_smiley", 75, ":D :D :D :D :D :D :D"}, ["price"] = {"Captain Price", "masks/ecg_price", 100, "Let\'s do this."}, ["link"] = {"Link", "masks/ecg_link", 100, "Mraa! Sraa! FERERAA!"}, ["homer"] = {"Homer Simpson", "masks/ecg_homer", 150, "Mmmmm... Donuts..."}, ["scatman"] = {"Scatman", "masks/ecg_scatman", 200, "Scahpadahpadabedily..."}, ["devil"] = {"Devil", "masks/ecg_devil", 50, "Lucifer will claim your soul."}, ["tasmanian"] = {"Tasmanian Devil", "masks/ecg_tasmanian", 150, "Ralluhoffscosfhsfdksevcsff!"}, ["prime"] = {"Optimus Prime", "masks/ecg_prime", 200, "Autobots, roll out!"}, ["rich"] = {"Rich Guy", "masks/ecg_rich", 1000, "You're one rich mother fucker."}, ["john"] = {"John (Pufferfish)", "masks/ecg_john", 500, "Pufferfish's face...\nWear at your own risk."}, ["kane"] = {"Kane", "masks/ecg_kane", 125, "You can\'t kill the messiah."}, ["gir"] = {"Gir", "masks/ecg_gir", 200, "I wanna be a mongoose."}, ["heavy"] = {"Heavy", "masks/ecg_heavymask3", 300, "Custom Mask"}, ["renard"] = {"Renard", "masks/ecg_renard", 300, "Custom Mask"}, ["rainbowdash"] = {"Rainbow Dash", "masks/ecg_rainbowdash2", 300, "Sonic Rainboom!!!"} ["Anonymous"] = {"Anonymous", "masks/Anonymous", 750, "We are Anonymous"}, ["forever_alone"] = {"Forever. Alone", "masks/forever_alone", 125, "Rage comics forever alone"}, ["chuck"] = {"Chuck Norris", "masks/chuck", 2000, "Chuck Norris jokes anyone?"}, ["morsay"] = {"Morsay", "masks/morsay", 400, "Custom Mask"}, ["L"] = {"L Lawliet", "masks/L", 350, "Custom Mask"}, ["DIEUNOEL"] = {"Smiley", "masks/DIEUNOEL", 250, "Custom Mask"}, ["Ben"] = {"Ben Laden", "masks/Ben", 1500, "Custom Mask"}, ["batman"] = {"batman", "masks/batman", 500, "Custom Mask"}, ["noel"] = {"For Noël", "masks/noel_masque", 150, "Custom Mask"} } [/lua] Edit: The error was fixed! I accidentally made a typo. I get two new errors now though, [lua] Warning: Unhandled usermessage 'UpdateMasks' Warning: Unhandled usermessage 'Masks' [/lua] I am assuming it's coming from this part. [lua] usermessage.Hook( "Masks", function( um ) LocalPlayer().Masks = string.Explode( "\n", um:ReadString() ) RunConsoleCommand( "currentmask", GetConVar( "currentmask" ):GetString() ) SetupStore() end ) usermessage.Hook( "UpdateMasks", function( um ) LocalPlayer().Masks = string.Explode( "\n", um:ReadString() ) if Store then Store:Remove() SetupStore() end end ) [/lua]
  • Avatar of Aide
  • Ah, your using chief's mask store. I thought you were using a different one. According to one of your posts that file is being loaded by the client why? Should it not be loaded by both the client and the server? Also you can remove Store.* and return it back to what it was previous. [editline]3rd June 2012[/editline] The problem you seem to be having is the files are loading correctly. Is this an addon or did you just drop these in lua/autorun/ folder. If so I think it would be about time to convert to an addon.
  • Avatar of JohnsonBrown
  • Edit: The issue is resolved, I don't know why it was not working, but messing around seemed to make it work.