maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 01 May 2014 01:33 PM |
I have a shop script that distributes items based off a table that gets JSON'ed and reverse JSON'ed. Unfortunately, when I reverse JSON the string, it still says it can't use :GetChildren () on a string.
Here's my code: util = assert (LoadLibrary ('RbxUtility')); stringy = player.StuffKeeper; UnJSONing = util.DecodeJSON (stringy.Value);
game.Players.LocalPlayer.Changed:connect (function () if game.Players.LocalPlayer.TeamColor == BrickColor.new ('Really blue') then for i,v in pairs (UnJSONing:GetChildren) do -- errors --stuff end end end) |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 01 May 2014 01:41 PM |
| You also cant use :GetChildren() on a table ._. |
|
|
| Report Abuse |
|
|
|
| 01 May 2014 01:44 PM |
UnJSONing = LoadLibrary("RbxUtility").DecodeJSON(player.StuffKeeper.Value)
game.Players.LocalPlayer.Changed:connect(function() if game.Players.LocalPlayer.TeamColor == BrickColor.new ('Really blue') then for i=1,#UnJSONing do --stuff end end end) |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 01 May 2014 01:49 PM |
| I know, I know. I fixed that part already, but it just said that you can't use "pairs on a string". |
|
|
| Report Abuse |
|
|
|
| 01 May 2014 01:51 PM |
| that script i posted didnt work ? |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 01 May 2014 01:53 PM |
I tested the #UnJSONing method. The only problem is now I'm not sure how to refer to a single object in the string.
This is --stuff: for i,gear in pairs (game.ReplicatedStorage:GetChildren ()) do if v.Name == gear.Name and v then gear:Clone ().Parent = game.Players.LocalPlayer.Backpack; end end |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
| |
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 01 May 2014 02:11 PM |
| For shops I just use a string and gmatch. I find it much more reliable |
|
|
| Report Abuse |
|
|
|
| 01 May 2014 02:20 PM |
g = LoadLibrary("RbxUtility").DecodeJSON(player.StuffKeeper.Value)
game.Players.LocalPlayer.Changed:connect(function() if game.Players.LocalPlayer.TeamColor == BrickColor.new ('Really blue') then for i=1,#g do for i,gear in pairs (game.ReplicatedStorage:GetChildren ()) do if g[i] and g[i].Name == gear.Name then gear:Clone().Parent = game.Players.LocalPlayer.Backpack; end end end end end) |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 01 May 2014 03:30 PM |
I forgot about UnJSONing[i], thanks.
Wazap, could you explain that method? It sounds easier. |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 01 May 2014 03:32 PM |
It doesn't like it for some reason.
When I replace if v.Name with UnJSONing[i].Name, it gives me: attempt to index field ? (a nil value) |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 01 May 2014 03:38 PM |
Set it up like this
local shopItems = "Sword,Lightning rod,Pandas,Potatoes,Koalas" (no space in between commas preferably)
for s in shopItems:gmatch("%P+") do game.ServerStorage(s):clone().Parent = workspace end
Something like that |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 01 May 2014 03:40 PM |
1) I need to get better at string manipulation 2) How do you detect if a player has purchased the item? |
|
|
| Report Abuse |
|
|
|
| 01 May 2014 03:41 PM |
| Why not use a table instead of a string? |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 01 May 2014 03:42 PM |
| I do. I just have to use JSON so that person comes back with the items they've purchased after they left. |
|
|
| Report Abuse |
|
|
|
| 01 May 2014 03:43 PM |
| oh i understand what your trying to do btw you could also create int value for each wepon and then if int.Value == 1 then clonewepon else nowepon and just symply change that value to 1 |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 01 May 2014 03:44 PM |
what the heck are you trying to say?
IntValue? What's this method? BoolValue for every item is my last resort. |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 01 May 2014 03:46 PM |
| Use a StringValue called inventory and use StringValue.Value:match(s) |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 01 May 2014 03:46 PM |
| So, when someone buys something, it adds that name to the string? |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
| |
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 01 May 2014 03:49 PM |
so..
function bought (item) inventory = inventory..","..item.Name end
? |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 01 May 2014 03:51 PM |
inventory.Value = inventory.Value..name
|
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 01 May 2014 03:52 PM |
| Well... yeah. I'll try it! |
|
|
| Report Abuse |
|
|