|
| 22 Jan 2013 11:19 PM |
this is kind of an advanced topic.
local Utils = assert(LoadLibrary("RbxUtility")) local stats = { money = 123456; title = "1337 h4x04"; is_epic = true; awards = { kills10 = true; died20 = false; }; }
local JSON = Utils.EncodeJSON(stats)
local code = Utils.DecodeJSON(JSON)
for i = 1, #code do print(code[i][1]) end
What I want it to do is print the value of each key in the JSON code. |
|
|
| Report Abuse |
|
|
jrf2112
|
  |
| Joined: 29 Jun 2008 |
| Total Posts: 3354 |
|
|
| 22 Jan 2013 11:22 PM |
| And this isn't working, I assume? |
|
|
| Report Abuse |
|
|
| |
|
jrf2112
|
  |
| Joined: 29 Jun 2008 |
| Total Posts: 3354 |
|
|
| 22 Jan 2013 11:29 PM |
I see the problem. Your doing the stats incorrectly, the table is not arranged in numbers but in words.
You can't print it using a loop, only using code.money or code.title.
There is no code[1]. |
|
|
| Report Abuse |
|
|
|
| 22 Jan 2013 11:31 PM |
| Well, I'm doing this for an inventory system, for my Fallout 3 game, where you can hold as much stuff as you like. How do you recommend I get the items in your inventory? |
|
|
| Report Abuse |
|
|
jrf2112
|
  |
| Joined: 29 Jun 2008 |
| Total Posts: 3354 |
|
|
| 22 Jan 2013 11:35 PM |
weapons = { ["Primary"] = "assaultrifle"; ["Secondary"] = "submachine" }
inventory = {{food, "bread", 1}, {drink, "soda", 1}}
so, the inventory has a table in it with the item type, name, and quantity.
Maybe that? |
|
|
| Report Abuse |
|
|
|
| 22 Jan 2013 11:37 PM |
| Yeah. That would work, thanks :D |
|
|
| Report Abuse |
|
|
|
| 22 Jan 2013 11:42 PM |
Tried it. D: didn't work. Can you help me a little bit more? This is the code I did now that didn't work:
local Utils = assert(LoadLibrary("RbxUtility")) local stats = { cstats = { --table in the table TABLECEPTION kills = 100 -- random deaths = 5 -- random
}; }
local JSON = Utils.EncodeJSON(stats)
local code = Utils.DecodeJSON(JSON)
a = stats.cstats
for i = 1, #a do -- is supposed to get the keys of stats.cstats print(a[i]) end
the output isnt anything.
|
|
|
| Report Abuse |
|
|
jrf2112
|
  |
| Joined: 29 Jun 2008 |
| Total Posts: 3354 |
|
|
| 22 Jan 2013 11:47 PM |
Using the for loop in cstats is wrong. It's looking for cstats[i], so cstats 1. You did not post a 1 = in cstats, only a kills = .
try
local stats = { currentStats = {{"kills, 1337}, {"deaths", -1}} }
local JSON = Utils.EncodeJSON(stats)
local code = Utils.DecodeJSON(JSON)
current = stats.currentStats
for i = 1, current do print(current[i][1], current[i][2]) end |
|
|
| Report Abuse |
|
|
|
| 22 Jan 2013 11:49 PM |
| thx I tested and troubleshooted it since of typos and it now works :D |
|
|
| Report Abuse |
|
|
jrf2112
|
  |
| Joined: 29 Jun 2008 |
| Total Posts: 3354 |
|
| |
|