This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
jewelshisen's profile picture

Altering Tables

Started by jewelshisen, 23 April 2014 - 05:21 PM
jewelshisen #1
Posted 23 April 2014 - 07:21 PM
Is there a way that you can edit the value for a specific key in a table?

For example would this work?


local Status = {}
Status["Front"] = "Locked"
-- do stuff
Status["Front"] = "Unlocked"
Edited on 23 April 2014 - 05:29 PM
OReezy #2
Posted 23 April 2014 - 07:30 PM
Simply assign it value.
local table = {"one", "two", "three"}
print(table[2]) --> two
table[2] = "not two"
print(table[2]) --> not two

edit: Was typing this up as you edited your post. Yes, that works.
Edited on 23 April 2014 - 05:31 PM
Lyqyd #3
Posted 23 April 2014 - 07:31 PM
Yep. Since your key is a string literal without unusual characters or spaces, you could also use: Status.Front = "Locked"
jewelshisen #4
Posted 23 April 2014 - 07:32 PM
Simply assign it value.
local table = {"one", "two", "three"}
print(table[2]) --> two
table[2] = "not two"
print(table[2]) --> not two

edit: Was typing this up as you edited your post. Yes, that works.

Alright. Wasn't sure it would work. :)/>