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: Using _G with tables;

Previous Thread :: Next Thread 
sam8985 is not online. sam8985
Joined: 12 Nov 2011
Total Posts: 582
18 Aug 2013 02:04 AM
For some reason, it isn't working for me. I've defined _G.admins as {""}, but when I try to get it's length (#_G.admins) it outputs "attempt to get length of nil field" or something. Any ideas, or alternatives?
Report Abuse
Cakins is not online. Cakins
Joined: 23 Jul 2009
Total Posts: 307
18 Aug 2013 02:38 AM
It will work. Keep in mind that global (or whatever the 'technical' term for them is) variables cannot be accessed in local scripts. I feel like you might be doing that. Otherwise it is just an oversight of overwriting its name.
Report Abuse
sam8985 is not online. sam8985
Joined: 12 Nov 2011
Total Posts: 582
18 Aug 2013 02:40 AM
No, I didn't use a localscript to access it, or make it.
Also, is there any way to turn a string into a table?
Like
Change
"example,table,one,two"
to
{example,table,one,two"}
?
Report Abuse
Cakins is not online. Cakins
Joined: 23 Jul 2009
Total Posts: 307
18 Aug 2013 02:44 AM
Not really sure what you mean here. Do you mean tern them into non-strings? Like variables? Because I think there is a way to do that, though I have never used it nor do I remember how to. Otherwise:

newstring = "example,table,one,two"

newtable = {}

table.insert(newtable, newstring)
Report Abuse
sam8985 is not online. sam8985
Joined: 12 Nov 2011
Total Posts: 582
18 Aug 2013 02:48 AM
That's not what I mean:

I meant turning
"example,la,lo,li"
into
{"example","la","lo","li"}
Report Abuse
Cakins is not online. Cakins
Joined: 23 Jul 2009
Total Posts: 307
18 Aug 2013 02:54 AM
I think like half of the string functions can do that. I would recommend this:

newtable = {}

for a in string.gmatch("example,la,lo,li", "%a+") do
table.insert(newtable, a)
end

for a, b in pairs(newtable) do
print(b)
end
Report Abuse
sam8985 is not online. sam8985
Joined: 12 Nov 2011
Total Posts: 582
18 Aug 2013 03:14 AM
Back to my original problem; still doesn't work. Apparently a "nil value".
Report Abuse
Apatheia is not online. Apatheia
Joined: 16 Aug 2013
Total Posts: 198
18 Aug 2013 03:42 AM
That's because the script that defines the field in _G may execute before the scripts that tries to access it, it's asynchronous. So you should wait before trying to do anything with it

repeat wait() until _G.admins

And yes, it's possible, there's a libary that let's you convert the table to a JSON string and viceversa

utils = LoadLibrary("RbxUtility")
tab = {"hi", 3, "apple", pie = ":D", "map1"}
encoded = utils.EncodeJSON(tab)
print(encoded)
for k,v in pairs(utils.DecodeJSON(encoded)) do
print(k,v)
end
Report Abuse
sam8985 is not online. sam8985
Joined: 12 Nov 2011
Total Posts: 582
18 Aug 2013 04:00 AM
I actually already tried that. It didn't work, it just stopped the script from running further.
Report Abuse
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
18 Aug 2013 05:00 AM
Perhaps this is yet another broken feature.. because I know for sure it at least used to work.. but I also know that Roblox has broken the coroutine sandbox, and many other items here lately, sooo yeah, you may just be working around roblox's messups..
Report Abuse
sam8985 is not online. sam8985
Joined: 12 Nov 2011
Total Posts: 582
18 Aug 2013 05:29 AM
Hm... Ok. I'll just put a StringValue into workspace and use that instead for the time being.
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