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 » Scripters
Home Search
 

Re: how are tables useful??

Previous Thread :: Next Thread 
ArknausRIP is not online. ArknausRIP
Joined: 24 Dec 2015
Total Posts: 516
11 Sep 2016 06:33 PM
i just learned how to make tables and I really don't see how they are useful.
Report Abuse
sc4rydev is not online. sc4rydev
Joined: 06 Nov 2015
Total Posts: 421
11 Sep 2016 06:34 PM
think of admin scripts, do you want a bunch of if player.name == or do you want to have it check a table of names they are very useful to store values that are player defined


Report Abuse
ArknausRIP is not online. ArknausRIP
Joined: 24 Dec 2015
Total Posts: 516
11 Sep 2016 06:35 PM
how would you make it check a table though???
Report Abuse
sc4rydev is not online. sc4rydev
Joined: 06 Nov 2015
Total Posts: 421
11 Sep 2016 06:46 PM
http://wiki.roblox.com/index.php?title=Table
http://wiki.roblox.com/index.php?title=Global_namespace/Table_manipulation


Report Abuse
kools is not online. kools
Joined: 11 Jan 2009
Total Posts: 1659
11 Sep 2016 07:07 PM
Tables are very useful because they allow us to keep track of many things with just one reference. If you want to do something to a large amount of objects, it's a lot easier to define a list and use that than to individually reference each object and do your operation. Example: ####### = {workspace.block1, workspace.block2, workspace.block3, workspace.block4} Instead of writing something like: workspace.block1.Transparency = 1 workspace.block2.Transparency = 1 workspace.block3.Transparency = 1 workspace.block4.Transparency = 1 I can do for position, part in ############## do part.Transparency = 1 end It's much more readable and flexible to changes. Tables are the best thing ever!
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
11 Sep 2016 07:09 PM
Tables are great because you can replace string values and bool values with tables.

local string = 'hi'
local bool = false

local tab = {}

table.insert(tab,string)
table.insert(tab,bool)

for i,v in next, tab do
print(i,v)
end

Output:

1 hi
2 false


Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
11 Sep 2016 07:16 PM
you can use tables for everything and a lot of roblox functions require and return tables
Report Abuse
ArknausRIP is not online. ArknausRIP
Joined: 24 Dec 2015
Total Posts: 516
11 Sep 2016 10:05 PM
@TimeTicks

wouldn't you have to add a number for order to that?

ocal string = 'hi'
local bool = false

local tab = {}

table.insert(tab,string, 1)
table.insert(tab,bool, 2)

for i,v in next, tab do
print(i,v)
end

Output:

1 hi
2 false
Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
11 Sep 2016 10:07 PM
and you can also do things for lists that can change

local test = {"hello","guys"}

coroutine.wrap(function() while wait(1) do print(table.concat(test," ")) end end)()

wait(2)

test[#test+1] = "lol!"
Report Abuse
ArknausRIP is not online. ArknausRIP
Joined: 24 Dec 2015
Total Posts: 516
11 Sep 2016 10:10 PM
*local
Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
11 Sep 2016 10:13 PM
and the instances and value types of roblox are all tables that have metatables, so you couldnt make any of those without them, even if they act differently

--example of making an 'object' without metatables
local object = {
Name = "hi";
Text = "derp;
}

print(object.Name)
print(object.Text)

--this is basically a dictionary
--but with metatables, you can share functions and other keys with tables as you create them, and they can act differently from tables
Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
11 Sep 2016 10:14 PM
*from regular tables

and emphasis on "roblox" when i said value types
Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
11 Sep 2016 10:15 PM
i do have a question about Enums though, do they also use metatables and when you print them, their tostring function is their Enum path?
Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
11 Sep 2016 10:17 PM
nevermind i answered it myself yes it is
Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
11 Sep 2016 10:18 PM
if you call getmetatable on any value *SPECIFIC TO ROBLOX* like an Enum, an Instance, a Vector3, a CFrame (created with the new() function or an index to one) it will say "The metatable is locked"
Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
11 Sep 2016 10:19 PM
but things like strings in lua already have metatables weirdly enough, probably just so they can share the functions
Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
11 Sep 2016 10:21 PM
so all of the value types specific to roblox are tables and/or userdata, they are just treated different ways because of the C/C++ code and also the shared metatables
Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
11 Sep 2016 10:24 PM
so tl;dr

tables are used a lot outside of the normal lua scripting on roblox to make most of the engine itself

and they can be used for a lot of different things while scripting lua in roblox or a lua program
Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
11 Sep 2016 10:25 PM
and userdatum basically have similar functions to tables but are much better, only can be used in C though because of the security restrictions
Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
11 Sep 2016 10:25 PM
can only be used outside of lua*
sorry for typos lol
Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
11 Sep 2016 10:30 PM
they are also great for
1) organizing and sorting data
2) reading data
3) storing / saving / loading data
4) using data that can change (with multiple items such as children of a parent, or a key of a dictionary and so forth)
5) doing multiple things to certain items without doing each by hand
7) iterating through lists to do something with each value
8) storing variables from a module into the environment
9) OOP
10) etc
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
12 Sep 2016 09:51 AM
@OP no you don't have to add numbers to that. table.insert will automatically go to the next index, those parameters are there to force the value to be inserted at the index you want.


Report Abuse
Milenveliki is not online. Milenveliki
Joined: 14 Aug 2013
Total Posts: 1097
12 Sep 2016 10:01 AM
iv i wantz uz string.gsub instead :P
Report Abuse
Milenveliki is not online. Milenveliki
Joined: 14 Aug 2013
Total Posts: 1097
12 Sep 2016 10:02 AM
u*
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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