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: _G and table manipulation

Previous Thread :: Next Thread 
DaneelOlivaw is not online. DaneelOlivaw
Joined: 14 Apr 2012
Total Posts: 661
04 May 2013 04:33 PM
So I need to add an extra column to a table I have. I've got a sort of problem I've been working on for a while, posted about it previously, and was given a script example I didn't understand with two things:

_G and table.insert.

Simply stated, I want some clarification on the purposes of these things, what they do, all that kind of stuff, because I never use something I don't understand.
Report Abuse
masterblokz is not online. masterblokz
Joined: 17 Nov 2010
Total Posts: 9517
04 May 2013 04:38 PM
_G is a global function

table.insert inserts something into a table
for example

ok = {}
for i, v in pairs(game.Workspace:GetChildren()) do
table.insert(ok,v.Name)
end
Report Abuse
DaneelOlivaw is not online. DaneelOlivaw
Joined: 14 Apr 2012
Total Posts: 661
04 May 2013 06:47 PM
What is the purpose of a global function, then?

As well as that, how would I reference the new information I would have in the generated column? How would I define said information in the first place?
Report Abuse
MassiveGman is not online. MassiveGman
Joined: 23 Jan 2011
Total Posts: 2019
04 May 2013 06:51 PM
global functions:

lua*learners.org*/tutorial?tut=155

remove *'s




|MassiveGman| "I reject your reality and substitute my own"
Report Abuse
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
04 May 2013 06:53 PM
lualearners.org

?

I don't see what's wrong with the link, but just use 'lua.bz' I guess.
Report Abuse
DaneelOlivaw is not online. DaneelOlivaw
Joined: 14 Apr 2012
Total Posts: 661
04 May 2013 07:34 PM
I don't understand the purpose behind a global function. Wouldn't you be able to do all of that with a normal function?
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
04 May 2013 07:35 PM
_G is a table not a function....

You can see this by: print(type(_G))
Report Abuse
DaneelOlivaw is not online. DaneelOlivaw
Joined: 14 Apr 2012
Total Posts: 661
04 May 2013 08:00 PM
... A misnomer can be an annoying thing indeed.

So let's say I'm using getChildren() but I need to add an additional column to it. I'm assuming that in this case, I need to use _G because the table getChildren() returns is read-only- meaning that _G will be an editable copy of it.

In this case, what if I need more than one table? And why shouldn't I define my own tables like how I define my own values (assuming it's possible)?
Report Abuse
xXxMoNkEyMaNxXx is not online. xXxMoNkEyMaNxXx
Joined: 03 Oct 2008
Total Posts: 3120
04 May 2013 08:05 PM
Adding an additional column can be emulated by wrapping the original table in another table, and adding another table index to the wrapper as your 'new column'.
Report Abuse
DaneelOlivaw is not online. DaneelOlivaw
Joined: 14 Apr 2012
Total Posts: 661
04 May 2013 10:19 PM
I suppose I'm asking the wrong questions.

What is _G? What I know is that it's a 'global table'. What I don't know is when it should be used, and what for.

How do I add things to a table and reference them later? I'll take your method for emulation, so long as it works the same, but if I can't do what I need to then it doesn't matter either way.
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
05 May 2013 10:37 AM
Theres 2 types of _G.

Serverside _G, and clientside _G.

Serverside _G runs in the server, and is used by scripts.
Clientside _G runs in each client(each client has their own) and is used by localscripts.

Here are a few examples:


You could for example have this in a script:

LOL = "asd"
function _G.MYFUNC()
print(LOL)
end

and this in another script:

_G.MYFUNC()

>LOL
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
05 May 2013 10:38 AM
It would print "asd", not "LOL", sorry im dumb
Report Abuse
DaneelOlivaw is not online. DaneelOlivaw
Joined: 14 Apr 2012
Total Posts: 661
05 May 2013 03:13 PM
Now I'm really confused. I've been told it's a function, then a table, and then a function again.

And would I need it at all if I was using only a single script for something?
Report Abuse
ScrewDeath is not online. ScrewDeath
Joined: 03 Jun 2012
Total Posts: 2700
05 May 2013 03:18 PM
If it's just in one script, no.
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