Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Question about Tables? [ANSWERED IN COMMENTS]

Asked by 9 years ago

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?

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 ProfessorSev 220 — 9y
0
thanks mate! fahmisack123 385 — 9y
0
your welcome ProfessorSev 220 — 9y

2 answers

Log in to vote
4
Answered by
Necrorave 560 Moderation Voter
9 years ago

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

Ad
Log in to vote
2
Answered by 9 years ago

the second line would overwrite the first one.

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

Answer this question