Changing index of value in the table

This is what i am trying to achieve:

This is table before:
local Table = {}

And i want to add value to it like this:
local Table = {["Basic Color"] = Color3.new(0,0,0)}

Yeah that is pretty much it. :grin:

1 Like
table.insert(Table, ["Basic Color"] = Color3.new(0,0,0))
local Table = {}

Table["Basic Color"] = Color3.new(0,0,0) -- yay
print(Table)

@kelvinsverdlov1 that is not valid syntax

3 Likes

My bad, I’ll note that. Haven’t used lua in a while.

1 Like

I was curious (sometimes Lua supports weird syntax no one uses), looks like this isn’t valid syntax.

lua: main.lua:3: unexpected symbol near '['

["Basic Color"] = Color3.new(0,0,0) doesn’t become an object, so this isn’t possible.

Insert parameter descriptions:

  • tableVal: This is the table structure in which the value newValue is to be inserted.
  • index: This is a numeric value that specifies the position in tableVal in which the value newValue is to be inserted. This is an optional parameter.
  • newValue: This is the value that we want to insert in tableVal.

Source: Educative Answers - Trusted Answers to Developer Questions

So you can’t replace the insert index with a string either–it has to be numerical.

RickAstll3y has the correct way to set an index in the dictionary portion of the table.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.