|
| 05 Jan 2015 02:22 PM |
As far as I am aware _G.table = {""} This creates a global table that I can access to store and delete data to/from? Is that correct? If so, how can I rename the table, and how can I put things in it and delete everything in it from another script? Thanks jj |
|
|
| Report Abuse |
|
|
| |
|
| |
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 05 Jan 2015 02:31 PM |
_G.Thing = {}; _G.Thing.A = "Lel"; local n = _G.Thing; _G.Thing = nil; _G.Otherthing = n; n = nil; print(_G.Otherthing.A) |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2015 02:35 PM |
| Thx - so does that script create a global table and put something in called lel, and another table called thing and another called overthing? Would those work in another script? |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 05 Jan 2015 02:39 PM |
| That makes a table in the _G table called thing, and then it renames thing to Otherthing very inefficiently |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2015 02:41 PM |
| Ah ok! Thanks - so very simply, I could create a global table, and put something in it from another script and delete it from another script? But how? |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 05 Jan 2015 02:46 PM |
| The same way as any other table. |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2015 02:48 PM |
Ah ok! Cool! Thanks! Just one last question... I create a table called like this like this - _G.Escapers = { } From another script, do I have to "call" it with the _G.? Or can I just put stuff in it using the Escapers = { }?
|
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 05 Jan 2015 02:50 PM |
You have to use the _G
Because Roblox. |
|
|
| Report Abuse |
|
|
| |
|
|
| 05 Jan 2015 02:57 PM |
Oh - another quick question xD
_G.Thing.A = "Lel";
Why did you put the ".A" ??
|
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
| |
|
|
| 05 Jan 2015 03:05 PM |
| Why do you have to put ".A" though? What does that do? |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 05 Jan 2015 03:08 PM |
Stops you from overwriting the table -.-
It didn't have to be A It just was. |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2015 03:10 PM |
Tables can be accessed three ways:
1. tableVariable.key 2. tableVariable["key"] 3. rawget(table, "key")
Note that with methods 2 and 3 you can use integers or even variables as indexes. _G is a variable holding a table. It works just like any other variable that holds a table. |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2015 03:12 PM |
OK thanks! So now, In a script I have _G.Escapers = {} which creates the global table and in another script I have
script.Parent.Touched:connect(function(hit)--when the brick is touched print ("Player touched!") for key, value in next, _G.Escapers do if value == hit.Parent.Name then return end end table.insert(_G.Escapers, hit.Parent.Name) end); game.Workspace.Time.Changed:connect(function(newValue) if newValue == 0 then --if the time is equal to 1 then hdd= game.Workspace.Announcer end if _G.Escapers == 0 then hdd.Text = "Nobody Escaped." else hdd.Text = "The players that Escaped are: "..table.concat(+G.Escapers, ", "); --display the winners in a message wait(3) hdd.Text = "" for key, value in next, _G.Escapers do local c = game.Players[value].leaderstats.Coins c.Value = c.Value + 10; end end end);
All look right? Thanks! jj
|
|
|
| Report Abuse |
|
|
Crythox
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 1188 |
|
|
| 05 Jan 2015 03:15 PM |
Don't get confused.
Clients get their own global table. So, for example, if you tried adding something to a server global table from a client's table, it would add to the client's table. Not to to the server.
To make things clear, any script in each player's PlayerGui, Backpack, etc, it accesses their own personal global table. |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2015 03:16 PM |
OK, thanks. Both these scripts are in the workspace, so would the second work by adding the names of players that touch the brick to the global table? |
|
|
| Report Abuse |
|
|
Crythox
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 1188 |
|
|
| 05 Jan 2015 03:17 PM |
Did you order biscuits from the bakery?
Yup it will work. |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2015 03:19 PM |
"Did you order biscuits from the bakery?" - What?? :D
OK, thanks! The reason I am using a global table is that I have more than one brick with that script in - they all need somewhere to add the players names to!! |
|
|
| Report Abuse |
|
|
Crythox
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 1188 |
|
|
| 05 Jan 2015 03:37 PM |
| In that case you should use one master script. |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 05 Jan 2015 05:02 PM |
1. tableVariable.key
I thought that was only for metatables. I should learn what those are lol |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2015 04:12 AM |
| @Cry - I can't just use one script as I need to create the global table and then in other scripts, check if they touch the brick and if they do, add them to the global table. Is there more of an efficient way to do that, then? :D |
|
|
| Report Abuse |
|
|
Crythox
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 1188 |
|
|
| 06 Jan 2015 11:14 AM |
My son, there is always a more efficient way to do something.
I suggest pulling all the code in one script using RemoteFunctions if you need to do something to the client. Of course there is always in pairs loops. |
|
|
| Report Abuse |
|
|