A Roblox Community
Would you like to react to this message? Create an account in a few clicks or log in to continue.

A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomeLatest imagesRegisterLog in
If you're a experienced coder make some tutorials! It would really help the site grow.
Make sure you read the rules(Which can be found by clicking here)
If you're a beginner at coding, try some tutorials.
We have many Moderators/Admins watching this site. Contact them with Questions.
Let us know what your favorite sport is. By clicking here to vote (Click here)
This site is becoming inactive. Lets make it active.
Log in
Username:
Password:
Log in automatically: 
:: I forgot my password
Top posters
blueymaddog
TABLES!!!! Vote_lcapTABLES!!!! Voting_barTABLES!!!! Vote_rcap 
naknak
TABLES!!!! Vote_lcapTABLES!!!! Voting_barTABLES!!!! Vote_rcap 
Supernapalm
TABLES!!!! Vote_lcapTABLES!!!! Voting_barTABLES!!!! Vote_rcap 
m27frogy
TABLES!!!! Vote_lcapTABLES!!!! Voting_barTABLES!!!! Vote_rcap 
slayer9365
TABLES!!!! Vote_lcapTABLES!!!! Voting_barTABLES!!!! Vote_rcap 
myrco919
TABLES!!!! Vote_lcapTABLES!!!! Voting_barTABLES!!!! Vote_rcap 
branefreez
TABLES!!!! Vote_lcapTABLES!!!! Voting_barTABLES!!!! Vote_rcap 
ninga95
TABLES!!!! Vote_lcapTABLES!!!! Voting_barTABLES!!!! Vote_rcap 
CloneTrooper787
TABLES!!!! Vote_lcapTABLES!!!! Voting_barTABLES!!!! Vote_rcap 
raboy117
TABLES!!!! Vote_lcapTABLES!!!! Voting_barTABLES!!!! Vote_rcap 
Top posting users this month
No user
Latest topics
» Where to go from here.
TABLES!!!! EmptySeptember 14th 2020, 1:20 pm by MrNicNac

» Send me an Email
TABLES!!!! EmptySeptember 14th 2020, 1:16 pm by MrNicNac

» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]
TABLES!!!! EmptyJuly 6th 2015, 7:38 pm by m27frogy

» New Site Possibly
TABLES!!!! EmptyJuly 6th 2015, 4:16 pm by m27frogy

» Ambassador!
TABLES!!!! EmptyApril 15th 2015, 11:40 pm by naknak

» Boop - Tag
TABLES!!!! EmptyApril 13th 2015, 9:46 pm by naknak

» Vip Class Script
TABLES!!!! EmptyApril 13th 2015, 4:54 pm by naknak

» Who's active?!
TABLES!!!! EmptyApril 13th 2015, 4:52 pm by naknak

» Genesis Point
TABLES!!!! EmptyJuly 17th 2014, 7:04 pm by branefreez

» Reward System
TABLES!!!! EmptyJuly 17th 2014, 5:41 am by m27frogy

» Script Request
TABLES!!!! EmptyJuly 10th 2014, 11:43 am by naknak

» local scripts?
TABLES!!!! EmptyJuly 10th 2014, 11:39 am by naknak

» Project: Reconstruction [Died]
TABLES!!!! EmptyJuly 10th 2014, 11:36 am by naknak

» Hi. I am new here
TABLES!!!! EmptyApril 26th 2014, 4:01 pm by altshiftkey

» What's your favorite sport?
TABLES!!!! EmptyJanuary 1st 2014, 2:13 pm by m27frogy

» FlashLight Script
TABLES!!!! EmptyJanuary 1st 2014, 2:11 pm by m27frogy

» Gun Making! [READ DESC]
TABLES!!!! EmptyJanuary 1st 2014, 2:10 pm by m27frogy

» Hi, I am new here!
TABLES!!!! EmptyNovember 26th 2013, 3:33 pm by Keanu73

» Improve Coding
TABLES!!!! EmptyOctober 26th 2013, 1:12 pm by pook03

» Simple Button
TABLES!!!! EmptySeptember 1st 2013, 6:19 pm by branefreez


 

 TABLES!!!!

Go down 
4 posters
AuthorMessage
Guest
Guest
avatar



TABLES!!!! Empty
PostSubject: TABLES!!!!   TABLES!!!! EmptyJanuary 28th 2011, 9:25 pm

This is my third tutorial on this site. All you really need to know about is variables and basic data types (numbers, strings, etc.) to understand this tutorial.

First things first, what exactly are tables? These aren't tables that you eat and do homework on, tables in programming are used for storing information. Another word you might use when talking about tables is arrays.

The first thing you should learn is how to create a table. It's actually very simple, you just use a set of braces:

Code:
{ }

Yeah, that's what those squiggly things are called. Now, like I said, tables store data and information, so let's put some data in our table. We'll give it two numbers; 3 and 7.

Code:
{ 3, 7 }

See how I seperated each value with a comma? That's how you set up a table. Now, usually, you're going to set a variable to your table, so let's name our table x.

Code:
x = {3,7}

Now, let's try and retrieve some of the information in that table.

Code:
print(x[3])

That will print nil. Why, you may ask? Well, even though we have the value of 3 in our table, we can't find it like that, because you use the index to find things in tables. Tables are set up like this:

Code:
 { Index = Value,
Index = Value,
Index = Value,
etc. }

The indices (plural for index) is how you find them in the table. But now you may be wondering how to find our value in table x, right? We've assigned 3 and 7 as values, and we haven't set any indices to be able to find them with. Right?

Well, in a way, that could be correct, but too bad. That's wrong.

When you don't manually set indices, they automatically become numbers that correspond with the position something is in the table. For example, since 3 is the first value in table x, it has the index of 1. So now, we'll use brackets (the box things) to find the first value of x.

Code:
print(x[1])

That'll give us 3 in the output. Since 7 is the second value, you would obviously use x[2] to find it.

Tables in Lua can hold any type of value, and they can be assigned to indices of either numbers or strings.

Code:
y = {"Forty-two", Seven = 42}

In that example, we made variable y, and set it to a table, with index 1 being the string "Forty-two", and index Seven (not 7) being the number 42. Now, if we print y[1], it gives us Forty two in the output.

But now, if we print y[2], it will give us 'nil'. Why do you think that is? well, we gave the second value a string index, so it doesn't have a numerical index anymore.

To access string indices, you can do it in two ways. Either the same way that numeric indices are found:

Code:
print(y["Seven"])

Or using a period, just like if you were to go down the hierarchy of the game (game.Workspace.Part).

Code:
print(y.Seven)

Both of those examples would print 42.

You can also put other types of data as your values, such as functions, objects, or even other tables :O

Here's a slightly more complex table:

Code:
Table1 = {"Potatoes",
urmom = {Pie = "Insert potato here", 51},
lolwuttt = "HAI"}

Now, see if you can figure out what each of these would print (note, some might print nil, so don't assume they have to be correct :P):

Code:
 print( Table1.lolwuttt )

print( Table1[1])

print( Table1.urmom[2] )

print( Table1.Pie )

If you can figure all of them out without actually running the code, then good for you ^_^. Under this spoiler is the answers to what each would print:

Spoiler:

If you have any questions, comments, feedback, or cookies, then leave a comment below :D


Last edited by NotAPotato on January 28th 2011, 11:53 pm; edited 1 time in total (Reason for editing : Typo. Thanks Supernapalm D:)
Back to top Go down
Supernapalm
Expert Scripter
Expert Scripter
avatar


Posts : 393
Join date : 2011-01-17

TABLES!!!! Empty
PostSubject: Re: TABLES!!!!   TABLES!!!! EmptyJanuary 28th 2011, 11:20 pm

what's the spoiler supposed to say?
Back to top Go down
http://hackthissite.org
naknak
Administrator
Administrator
naknak


Posts : 878
Join date : 2010-07-30

TABLES!!!! Empty
PostSubject: Re: TABLES!!!!   TABLES!!!! EmptyJanuary 28th 2011, 11:41 pm

What the prints print
Back to top Go down
Supernapalm
Expert Scripter
Expert Scripter
avatar


Posts : 393
Join date : 2011-01-17

TABLES!!!! Empty
PostSubject: Re: TABLES!!!!   TABLES!!!! EmptyJanuary 28th 2011, 11:46 pm

if Urmom in the last script was capitalized, i think it would print 51
Back to top Go down
http://hackthissite.org
myrco919
Intermediate Scripter
Intermediate Scripter
myrco919


Posts : 190
Join date : 2011-01-21
Age : 26
Location : Holland

TABLES!!!! Empty
PostSubject: Re: TABLES!!!!   TABLES!!!! EmptyMarch 6th 2011, 4:15 pm

OMG NO WAY!

Now I know who CrazyPotato is here....
Back to top Go down
Guest
Guest
avatar



TABLES!!!! Empty
PostSubject: Re: TABLES!!!!   TABLES!!!! EmptyMarch 6th 2011, 9:25 pm

You seriously didn't know?? :o

I thought it would be obvious, with my humorously ironic username and everything...
Back to top Go down
Supernapalm
Expert Scripter
Expert Scripter
avatar


Posts : 393
Join date : 2011-01-17

TABLES!!!! Empty
PostSubject: Re: TABLES!!!!   TABLES!!!! EmptyMarch 6th 2011, 9:54 pm

do you ever edit your posts?
Back to top Go down
http://hackthissite.org
Guest
Guest
avatar



TABLES!!!! Empty
PostSubject: Re: TABLES!!!!   TABLES!!!! EmptyMarch 6th 2011, 11:03 pm

When I see a need to...

I went and fixed the errors I saw in the metatable thing...

And plus, I'm not used to the edit post feature, the only forums I've seen other than these are the Roblox forums :O

Why do you ask?
Back to top Go down
blueymaddog
Administrator
Administrator
blueymaddog


Posts : 1081
Join date : 2010-12-09
Age : 26

TABLES!!!! Empty
PostSubject: Re: TABLES!!!!   TABLES!!!! EmptyMarch 9th 2011, 6:53 am

nice simple tutorial!
Back to top Go down
myrco919
Intermediate Scripter
Intermediate Scripter
myrco919


Posts : 190
Join date : 2011-01-21
Age : 26
Location : Holland

TABLES!!!! Empty
PostSubject: Re: TABLES!!!!   TABLES!!!! EmptyMarch 19th 2011, 7:40 am

Well, you're crazypotato4 on roblox and here your name says that you're not a potato olol.
Back to top Go down
myrco919
Intermediate Scripter
Intermediate Scripter
myrco919


Posts : 190
Join date : 2011-01-21
Age : 26
Location : Holland

TABLES!!!! Empty
PostSubject: Re: TABLES!!!!   TABLES!!!! EmptyMarch 19th 2011, 7:41 am

Btw, no need to yell out 'TABLES!!!!'.
Back to top Go down
Guest
Guest
avatar



TABLES!!!! Empty
PostSubject: Re: TABLES!!!!   TABLES!!!! EmptyApril 23rd 2011, 7:14 pm

Well, thank you Potato!
Back to top Go down
blueymaddog
Administrator
Administrator
blueymaddog


Posts : 1081
Join date : 2010-12-09
Age : 26

TABLES!!!! Empty
PostSubject: Re: TABLES!!!!   TABLES!!!! EmptyNovember 20th 2011, 6:31 am

:o you lied to me, crazy. I asked wether you were crazypotato or not and u said u weren't :0
Back to top Go down
Sponsored content





TABLES!!!! Empty
PostSubject: Re: TABLES!!!!   TABLES!!!! Empty

Back to top Go down
 
TABLES!!!!
Back to top 
Page 1 of 1
 Similar topics
-
» Tables..............

Permissions in this forum:You cannot reply to topics in this forum
A Roblox Community :: Tutorials and Resources :: Beginner-
Jump to: