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 » Scripters
Home Search
 

Converting a string to a table?

Previous Thread :: Next Thread 
DPLX is not online. DPLX
Joined: 10 Dec 2014
Total Posts: 768
26 Jan 2015 08:31 PM
Is there any easy way to do this?

Ex:

"{1,2,3,4}" -> table = {1,2,3,4}

:)
Report Abuse
DoctorBloxor is not online. DoctorBloxor
Joined: 07 Feb 2012
Total Posts: 3222
26 Jan 2015 08:32 PM
If I remembered all the fancy script commands I could probably help...


(But I don't, sorry)
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
26 Jan 2015 08:33 PM
-----
str = "{1,2,3,4}"
tble = loadstring(str)()
-----
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
26 Jan 2015 08:33 PM
Just use JSON encoded tables, it is more correct.
Report Abuse
DoctorBloxor is not online. DoctorBloxor
Joined: 07 Feb 2012
Total Posts: 3222
26 Jan 2015 08:33 PM
Or what Erternal said.

LUL
Report Abuse
DPLX is not online. DPLX
Joined: 10 Dec 2014
Total Posts: 768
26 Jan 2015 08:34 PM
Is there a way to do it without loadstring?

Doesn't LoadStringEnabled allow hackers and all that or something

I dont remember -_-

:)
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
26 Jan 2015 08:35 PM
Not really. Not if you use FE.

But just use JSON tables.
Report Abuse
DPLX is not online. DPLX
Joined: 10 Dec 2014
Total Posts: 768
26 Jan 2015 08:37 PM
So something like

JSONDecode(JSONEncode('{1,2,3,4}'))

?

I know its not correct syntax but you get the idea

I don't know a lot about JSON :(

:)
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
26 Jan 2015 08:39 PM
It's pretty much that, but JSONEncode takes a table, and JSONDecode takes a string. JSONs actually have square brackets, not the curly ones.
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
26 Jan 2015 08:40 PM
Correction to my post:
-----
str = "{1,2,3,4}"
tble = loadstring("return "..str)()
-----
Yes, loadstring may increase vulnerability to exploits.

Use for loops and string.gmatch to iterate through the string and look for strings matching ".+," and ",.+", then use string.sub to remove the commas.
Report Abuse
DPLX is not online. DPLX
Joined: 10 Dec 2014
Total Posts: 768
26 Jan 2015 08:41 PM
Alright, I think I got it now.

Thanks!

:)
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
26 Jan 2015 08:42 PM
Don't bother trying to your own tokenization function. JSON will support multidimensional tables, different datatypes, libraries, etc. It's so much easier to use too.
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
26 Jan 2015 08:47 PM
local tab = "{1,2,3,4}"

function makeTable(str)
    local tab = {}
    for i in str:gmatch("%d") do
        table.insert(tab,i)
    end
    return tab
end

local tabl = makeTable(tab)

print(unpack(tab1));
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
26 Jan 2015 08:50 PM
@goul

"for i in str:gmatch("%d") do"
Only works for numbers. Use .+ instead.

But yes, just use JSON.
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
26 Jan 2015 08:51 PM
+*
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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