generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Help With JSON

Previous Thread :: Next Thread 
wolverine12 is not online. wolverine12
Joined: 20 Aug 2008
Total Posts: 1100
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 is not online. jrf2112
Joined: 29 Jun 2008
Total Posts: 3354
22 Jan 2013 11:22 PM
And this isn't working, I assume?
Report Abuse
wolverine12 is not online. wolverine12
Joined: 20 Aug 2008
Total Posts: 1100
22 Jan 2013 11:24 PM
Yeah.
Report Abuse
jrf2112 is not online. 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
wolverine12 is not online. wolverine12
Joined: 20 Aug 2008
Total Posts: 1100
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 is not online. 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
wolverine12 is not online. wolverine12
Joined: 20 Aug 2008
Total Posts: 1100
22 Jan 2013 11:37 PM
Yeah. That would work, thanks :D
Report Abuse
wolverine12 is not online. wolverine12
Joined: 20 Aug 2008
Total Posts: 1100
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 is not online. 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
wolverine12 is not online. wolverine12
Joined: 20 Aug 2008
Total Posts: 1100
22 Jan 2013 11:49 PM
thx I tested and troubleshooted it since of typos and it now works :D
Report Abuse
jrf2112 is not online. jrf2112
Joined: 29 Jun 2008
Total Posts: 3354
22 Jan 2013 11:51 PM
Kewl.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image