Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 13 Jun 2012 09:09 PM |
> print(LoadLibrary('RbxUtility'):EncodeJSON({"Test"})) 21:08:50 - RbxUtility:185: Encoding of RbxUtility unsupported 21:08:50 - Script "RbxUtility", Line 185 - method WriteError 21:08:50 - Script "RbxUtility", Line 117 - method Write 21:08:50 - Script "RbxUtility", Line 481 21:08:50 - Script "print(LoadLibrary('RbxUtility'):EncodeJSON({"Test"}))", Line 1 21:08:50 - stack end
Does that make sense?
Can you not encode stuff in JSON yet? |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 13 Jun 2012 09:12 PM |
I don't think it ever will be, that's just a stud some dev wrote in when they were making the library script.
It's easy enough to write your own function for it though. Encoding is trivial, it's the decoding which is hard. |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 13 Jun 2012 09:16 PM |
How do would you decode/encode it, and is there a better way to create a way to request a function from the client.
What I have right now....
--- CLIENT SIDE ---
local Server = {} --So I can do.... Server.X("Test") setmetatable(Server, {})
local metatable = { __index = function(TheTable, Index) print("Server request for "..Index) return function(...) local RequestValue = Instance.new("StringValue") RequestValue.Name = Index RequestValue.Value = "" local ValuesToJSON = RbxUtility:EncodeJSON({...}) local Variables = Instance.new("StringValue", RequestValue) Variables.Name = "Vars" Variables.Value = ValuesToJSON Variables.Changed:connect(function() wait() print("Variables changed") local GottenValues = RbxUtility:DecodeJSON(Variables.Value) end) end end }
--- SERVER SIDE ---
local function SetupServerRequest(Functions, ServerPingOutTime) VerifyArg(ServerPingOutTime, "number", "ServerPingOutTime")
local function GetValuesFromFunction(...) local NewTable = {} for _, Value in pairs({...}) do NewTable[#NewTable+1] = Value end return NewTable; end
local NewServer = Instance.new("StringValue", game) NewServer.Archivable = false NewServer.Name = "Server" NewServer.ChildAdded:connect(function(Child) if Child and Child:IsA("StringValue") then if Functions[Child.Name] then local StartTime = tick() local FunctionArguments = {} local Vars = Child:FindFirstChild("Variables") if not Vars then repeat wait(0) Vars = Child:FindFirstChild("Variables") until Vars or tick()-StartTime >= ServerPingOutTime end if Vars then -- This way we know it's loaded... if Vars:IsA("StringValue") then FunctionArguments = RbxUtility:DecodeJSON(Vars.Value) local ReturnValues = GetValuesFromFunction(Functions[Child.Name](unpack(FunctionArguments))) local NewValues = RbxUtility:EncodeJSON(ReturnValues) Child.Value = NewValues else print("Vars is not the proper object type") end else print("Vars pinged out @ "..tick()-StartTime) end else print("Attempted to call a nil function") end else print("Child was not a string value...") end end) end
Should I just switch over to using values instead? How can I find out how to do this kind of thing with JSON, if that is the best thing to do.
:D?
|
|
|
| Report Abuse |
|
|
Ozzypig
|
  |
| Joined: 27 Mar 2008 |
| Total Posts: 4906 |
|
|
| 13 Jun 2012 09:48 PM |
nonono
You were using it on itself because of the colon. That's what the colon does - it passes the same object back to the function.
> print(LoadLibrary('RbxUtility').EncodeJSON({"Test"}))
I get ["Test"] |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 14 Jun 2012 01:52 PM |
Seems like it doesn't support anything other then normal table values. D:
Hmm.. |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 14 Jun 2012 04:28 PM |
| Yes, welcome to JSON. It can store strings, numbers, booleans, arrays, and dictionaries with string keys. Go to json.org to see the language definition on one easily-understandable page. |
|
|
| Report Abuse |
|
|