A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomeFAQRegisterLog 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
 
naknak
 
Supernapalm
 
m27frogy
 
slayer9365
 
myrco919
 
branefreez
 
ninga95
 
CloneTrooper787
 
raboy117
 
Top posting users this month
Latest topics
» Send me an Email
January 8th 2016, 10:14 am by naknak

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

» New Site Possibly
July 6th 2015, 4:16 pm by m27frogy

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

» Boop - Tag
April 13th 2015, 9:46 pm by naknak

» Vip Class Script
April 13th 2015, 4:54 pm by naknak

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

» Where to go from here.
April 13th 2015, 4:51 pm by naknak

» Genesis Point
July 17th 2014, 7:04 pm by branefreez

» Reward System
July 17th 2014, 5:41 am by m27frogy

» Script Request
July 10th 2014, 11:43 am by naknak

» local scripts?
July 10th 2014, 11:39 am by naknak

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

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

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

» FlashLight Script
January 1st 2014, 2:11 pm by m27frogy

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

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

» Improve Coding
October 26th 2013, 1:12 pm by pook03

» Simple Button
September 1st 2013, 6:19 pm by branefreez


Share | 
 

 TABLES!!!!

View previous topic View next topic Go down 
AuthorMessage
Guest
Guest



PostSubject: TABLES!!!!   January 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


Posts : 393
Join date : 2011-01-17

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

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

Posts : 878
Join date : 2010-07-30

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

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


Posts : 393
Join date : 2011-01-17

PostSubject: Re: TABLES!!!!   January 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
avatar

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

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

OMG NO WAY!

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



PostSubject: Re: TABLES!!!!   March 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


Posts : 393
Join date : 2011-01-17

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

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



PostSubject: Re: TABLES!!!!   March 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
avatar

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

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

nice simple tutorial!

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
myrco919
Intermediate Scripter
Intermediate Scripter
avatar

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

PostSubject: Re: TABLES!!!!   March 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
avatar

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

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

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



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

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

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

PostSubject: Re: TABLES!!!!   November 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

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
Sponsored content




PostSubject: Re: TABLES!!!!   

Back to top Go down
 
TABLES!!!!
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Charm tables again or???
» Power From Pain Tables
» Charm Tables for MH3U
» Eldar vs. Renegades
» Building my first terrain table, need advice

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