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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|