I want to table.insert something that would look like this:
local table1 = {
["randomname"] = 1
}
How do I insert something like that tho?
Ive tried table.insert(table, thingy1, thingy2) but thingy1 needs to be a number
I want to table.insert something that would look like this:
local table1 = {
["randomname"] = 1
}
How do I insert something like that tho?
Ive tried table.insert(table, thingy1, thingy2) but thingy1 needs to be a number
This is a dictionary.
table.insert
only works with arrays
.
You could try to do:
table1["randomname"] = 1
Hope I understood you correctly.
I basically want to insert a value.
Most of them are like
local a = {
1,
"ABC"
}
But I want to INSERT (I literally cannot edit an empty table, i need to INSERT) something like this:
local a = {
["ThisIsTheName"] = "This is the value"
}
In that case you can go ahead and do
a["ThisIsTheName"] = "This is the value"
Dude, i have to INSERT a value into an EMPTY table, for a nomination system!
local Table = {}
I have to insert inside the Table a type of value! ["ThisTypeOfValueDude"] = 1
I can’t edit an empty table what do you mean.
Is there a way to table.insert into an EMPTY TABLE, something like that?
Yes you can?
local t = {}
t["index"] = "value"
print(t.index) --> value
What you’re asking for is confusing. You’re asking how to insert a dictionary value, but you keep saying you can’t edit an empty table. table.insert
is only for arrays, and the correct syntax, as stated twice before, is table[index] = value
for dictionaries.
Thank you all for the suggestions, i found the cure myself.
Use dot operator syntax when defining string keys in a table, i.e;
local t = {}
t["Key"] = math.pi
t.Key = math.pi --Preferred syntax (only valid for string keys).