Jump to content




Altering Tables


  • You cannot reply to this topic
3 replies to this topic

#1 jewelshisen

  • Members
  • 164 posts

Posted 23 April 2014 - 06: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 by jewelshisen, 23 April 2014 - 06:29 PM.


#2 OReezy

  • Members
  • 91 posts

Posted 23 April 2014 - 06: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 by OReezy, 23 April 2014 - 06:31 PM.


#3 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 23 April 2014 - 06:31 PM

Yep. Since your key is a string literal without unusual characters or spaces, you could also use: Status.Front = "Locked"

#4 jewelshisen

  • Members
  • 164 posts

Posted 23 April 2014 - 06:32 PM

View PostOReezy, on 23 April 2014 - 06:30 PM, said:

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. :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users