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
 

Fixed And New: All About Tables (Arrays)

Previous Thread :: Next Thread 
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
21 Sep 2012 11:56 PM
So, a table (it's called array in most other scripting languages) is a variable that holds multiple values, it can range from integers to strings and instances.

-------------------------------------------------------------------------------
How you would start a table

TableName = {"Value1", 2.1234, game.Workspace:GetChildren()}
That would make a table with the values of: Value1, 2.1234, and an array of all the objects in workspace

Multi tables

UserInfo = {
{"Cnt", 12, 51, game.Players["CntKillMe"]},
{"Crus", 12, 51, game.Players["Crusada91"]}
}

Even triple/quadruple/etc tables work:
Lol = { { { { 1 }, {1}, 1 } , 1}, 1}
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
21 Sep 2012 11:57 PM
To insert into a table

table.insert(TableName, Value)

Example:

Usrs = {"cnt", "crus"}
table.insert(Usrs, "roblox"}

Then, Usrs will equal {"cnt", "crus", "roblox"}
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
21 Sep 2012 11:57 PM
To remove from a table

table.remove(TableName, Location)

Examples:

Usrs = {"cnt", "crus", "roblox"}
table.remove(Usrs, 2)

Then, Usrs will equal {"cnt", "roblox"}


Note:
Roblox's tables start from 1, most other languages start from 0

Example:

Roblox
Usrs = {"lol", "lol2", "lol3"}
Index of lol = 1, lol2 = 2, lol3 = 3

JavaScript
Usrs = ["lol", "lol2", "lol3"]
Index of lol = 0, lol2 = 1, lol3 = 2

PHP
$Usrs = Array("lol", "lol2", "lol3")
Index of lol = 0, lol2 = 1, lol3 = 2

VisualStudios
Dim Usrs = {"lol", "lol2", "lol3"}
Index of lol = 0, lol2 = 1, lol3 = 2
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
21 Sep 2012 11:58 PM
To view a value from a table

TableName[Index]

Example:
Usrs = {"lol", "lol2", "lol3"}
print(TableName[1])

That would print "lol"


To see if a value is contained in a table

Usrs = {"lol", "lol2", "lol3"}

if #Usrs == 0 then return end --Hashtag indicates the length of the table, if the table is empty then it will just stop running a function
for i = 1, #Usrs do --Start a for loop from 1 until amount of users [3 in this case]
if Usrs[i] == "lolz" then --Checks if the table[index] equals lolz
return true --It does!
end
end
return false --Aww

Note for other languages

To get length of array from:

JavaScript
ArrayName.length

PHP
count($ArrayName)

VisualStudios
UBound(ArrayName)


So, need help? Just comment and I will get to it asap
Report Abuse
rayoma is not online. rayoma
Joined: 13 Nov 2009
Total Posts: 1911
22 Sep 2012 12:59 AM
tab={
a=3;
b=tab;
};

print(tab.a);--3
print(tab.b.b.b.b.b.b.b.b.b.b.b.a);--3

c={};
c[true]=function() print("Yes"); end
c[false]=function() print("No"); end

c[ 1==1 ]();--Yes
c[ 1==2 ]();--No


Forgot that stuff
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