DiscoTrio
|
  |
| Joined: 08 Aug 2008 |
| Total Posts: 441 |
|
|
| 31 Dec 2012 01:20 PM |
Hello,
I am having a bit of an issue trying to load a string with the LoadString() method. This pcall function always returns the following:
Error: Argument 1 missing or nil.
Here is my script:
local ok, ret = pcall(function() return player:LoadString(items) end) if ok then local item_t = RbxUtility.DecodeJSON(ret) if #items_t > 0 then console("Loading " .. #item_t .. "items...") for i=1,#item_t do console("Loaded item: " .. item_t[i] .. ", ") game.Workspace.Items:findFirstChild(item_t[i]):Clone().Parent = player.Items end console("Done loading items. ") else console("Nothing to load. ") end else console("Error: " .. ret .. ". ") end
As you an see, the stuff in the middle (includint he decodejson thing) is not relevant to this error because PCall captures an error with this bit: local ok, ret = pcall(function() return player:LoadString(items) end)
Any ideas? |
|
|
| Report Abuse |
|
|
|
| 31 Dec 2012 01:25 PM |
line?
¬ LuaLearners Elite/Writer |
|
|
| Report Abuse |
|
|
DrHaximus
|
  |
| Joined: 22 Nov 2011 |
| Total Posts: 8410 |
|
|
| 31 Dec 2012 01:25 PM |
| Does the output specify which function is without an argument? |
|
|
| Report Abuse |
|
|
DiscoTrio
|
  |
| Joined: 08 Aug 2008 |
| Total Posts: 441 |
|
|
| 31 Dec 2012 01:28 PM |
It does not, because I am using pcall. Due to data persistence not working in solo or local server mode the console() function I made posts errors and such to the screen on the online server.
This means that we know that the error is coming from the pcall function... the only place it can be posted from.
So it appears to me that it has a problem with LoadString() |
|
|
| Report Abuse |
|
|
DiscoTrio
|
  |
| Joined: 08 Aug 2008 |
| Total Posts: 441 |
|
|
| 31 Dec 2012 01:29 PM |
This being the full function the error is coming from:
(function() return player:LoadString(items) end)
I know that the key "items" is valid as well as player. |
|
|
| Report Abuse |
|
|
|
| 31 Dec 2012 01:31 PM |
in that case item must be nil. post the rest of your script and i'll look at it.
¬ LuaLearners Elite/Writer |
|
|
| Report Abuse |
|
|
|
| 31 Dec 2012 01:31 PM |
| clearly, items = nil. Show us the rest of the script? |
|
|
| Report Abuse |
|
|
DiscoTrio
|
  |
| Joined: 08 Aug 2008 |
| Total Posts: 441 |
|
|
| 31 Dec 2012 01:32 PM |
Okay, I apologize for any formatting that the forum removes from the script:
game.Players.PlayerAdded:connect(function(player) local RbxUtility = LoadLibrary("RbxUtility") console_box = player.PlayerGui.MainMenu.main.console function console(new) console_box.Text = (console_box.Text .. " " .. new) end
wait() console("Begin waiting for data to be ready...") player:WaitForDataReady() console("Data ready! Placing main groups...")
local questGroup = Instance.new("StringValue", player) questGroup.Name = "Quests"
local itemGroup = Instance.new("StringValue", player) itemGroup.Name = "Items"
local money = Instance.new("NumberValue", player) money.Name = "Money" money.Value = 100
local messages = Instance.new("StringValue", player) messages.Name = "Messages"
game.Lighting.Levels:Clone().Parent = player
console("All main groups placed!") local ok, ret = pcall(function() return player:LoadString(items) end) if ok then local item_t = RbxUtility.DecodeJSON(ret) if #items_t > 0 then console("Loading " .. #item_t .. "items...") for i=1,#item_t do console("Loaded item: " .. item_t[i] .. ", ") game.Workspace.Items:findFirstChild(item_t[i]):Clone().Parent = player.Items end console("Done loading items. ") else console("Nothing to load. ") end else console("Error: " .. ret .. ". ") end end)
game.Players.PlayerRemoving:connect(function(player) player:WaitForDataReady()
local items = {} local item_t = player.Items:GetChildren() for i=1,#item_t do items[i] = item_t[i].Name end local succ, ret = pcall(function() player:SaveString('items', RbxUtility.EncodeJSON(items)) end) if succ then print("saved.") else print("Saving error", ret) end end) |
|
|
| Report Abuse |
|
|
DiscoTrio
|
  |
| Joined: 08 Aug 2008 |
| Total Posts: 441 |
|
|
| 31 Dec 2012 01:33 PM |
Here is a copy in pastebin:
pastebin.com/9eX4BavP |
|
|
| Report Abuse |
|
|
|
| 31 Dec 2012 01:34 PM |
| I honestly don't see 'items' defined anywhere. |
|
|
| Report Abuse |
|
|
|
| 31 Dec 2012 01:35 PM |
put quotes around 'items'.
¬ LuaLearners Elite/Writer |
|
|
| Report Abuse |
|
|
DiscoTrio
|
  |
| Joined: 08 Aug 2008 |
| Total Posts: 441 |
|
|
| 31 Dec 2012 01:35 PM |
(function() player:SaveString('items', RbxUtility.EncodeJSON(items)) end)
This happens at the bottom of the script when a player disconnects. |
|
|
| Report Abuse |
|
|
DiscoTrio
|
  |
| Joined: 08 Aug 2008 |
| Total Posts: 441 |
|
|
| 31 Dec 2012 01:43 PM |
| with quotes of the " and ' variety the script does not seem to execute past the pcall function or return errors. |
|
|
| Report Abuse |
|
|
|
| 31 Dec 2012 01:45 PM |
local item_t = RbxUtility.DecodeJSON(ret) if #items_t > 0 then
you got a typo. change item_t to items_t.
¬ LuaLearners Elite/Writer |
|
|
| Report Abuse |
|
|
DiscoTrio
|
  |
| Joined: 08 Aug 2008 |
| Total Posts: 441 |
|
|
| 31 Dec 2012 01:50 PM |
That was the error I spent the past day and a half on?
Thnaks a ton! Im in your debt :P |
|
|
| Report Abuse |
|
|
|
| 31 Dec 2012 01:51 PM |
i'm not sure if that will ultimately solve your problem... test it first
¬ LuaLearners Elite/Writer |
|
|
| Report Abuse |
|
|
DiscoTrio
|
  |
| Joined: 08 Aug 2008 |
| Total Posts: 441 |
|
|
| 31 Dec 2012 01:54 PM |
I have 3 monitors, a fast computer, and a can of Red Bull. I have tested this a dozen times since you pointed out the error.
:3 |
|
|
| Report Abuse |
|
|