Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Question about Tables? [ANSWERED IN COMMENTS]

Hi there guys. Just a quick question.

If I do this:

table = {"LOLO",5}
table = {7}

Then would the first line be erased/replaced? In other words, what would table be if I was to print it?

3 comments

2

table would then equal 7 only because u are setting it to a new set of value if u want to replace an item or add one then that would be achieved using table.insert or table.remove

0

thanks mate!

0

your welcome

2 answers

The entire table would be replaced with the new list you provided.

If you want to change values in the tables instead of the whole table, you would use the indexes.

Example:

-- Indexes:    [1]     [2]     [3]
local table = {"One", "Two", "Three"}
print (table[1]) -- Would print "One"

table[1] = 1 --Change the first index to '1'
print (table[1]) --Would print '1'

You can also manipulate to a table using table.insert() and table.remove()

Example:

local list = {"I", "Like", "Pie"} --Notice the name is "list"
table.insert(list, "a lot")--Add a new value to the end of the list

for x = 1, #list, 1 do
	print (list[x].." ") --Will print "I like Pie a lot"
end

table.remove(list, 4) --Remove what is placed in index '4'

for x = 1, #list, 1 do
	print (list[x].." ")--Will only print "I like Pie"
end

Let me know if you have any other questions!

More info on tables: http://wiki.roblox.com/index.php?title=Table

the second line would overwrite the first one.

table = {"LOLO",5}
table = {7}
print(table[1]) --prints 7

This discussion is preserved as it was. New answers, comments, and votes are closed.