Table = {}
Name = "some"
Table.? = "something"
My goal is that at Table.some store "something"
I tried that
Table.(Name) = "something"
But it still doesn't worked
Table insert name
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Table insert name
lua,contrary to other language,give you as much space as moon
Re: Table insert name
This is basic Lua. Did you search before posting?
Code: Select all
basic="search"
tutorials={}
tutorials[basic]=1
print (tutorials.search)
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
Re: Table insert name
Doesn't seem to quite workdusoft wrote: ↑Wed Oct 18, 2023 5:41 pm This is basic Lua. Did you search before posting?Code: Select all
basic="search" tutorials={} tutorials[basic]=1 print (tutorials.search)
When i try to print,it give me an error(nil value)like it actually don't put any value in the table
lua,contrary to other language,give you as much space as moon
Re: Table insert name
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
Re: Table insert name
It prints 1 correctly. Check your setup.soytak111 wrote: ↑Wed Oct 18, 2023 6:45 pmDoesn't seem to quite workdusoft wrote: ↑Wed Oct 18, 2023 5:41 pm This is basic Lua. Did you search before posting?Code: Select all
basic="search" tutorials={} tutorials[basic]=1 print (tutorials.search)
When i try to print,it give me an error(nil value)like it actually don't put any value in the table
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
Re: Table insert name
Let's make a function for it!
Now you can use it as
Code: Select all
local function insertKeyValue (tabl, key, value)
tabl[key] = value
end
Code: Select all
tutorials={}
basic = "search"
n = 1
insertKeyValue (tutorials, basic, n)
print(tutorials.search) -- prints 1
Re: Table insert name
That work! Its weird that it don't work in code but that the function workdarkfrei wrote: ↑Thu Oct 19, 2023 7:10 am Let's make a function for it!
Now you can use it asCode: Select all
local function insertKeyValue (tabl, key, value) tabl[key] = value end
Code: Select all
tutorials={} basic = "search" n = 1 insertKeyValue (tutorials, basic, n) print(tutorials.search) -- prints 1
lua,contrary to other language,give you as much space as moon
Re: Table insert name
Right:
Wrong:
Code: Select all
tutorials[basic] = 1
Code: Select all
tutorials.[basic] = 1
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 19 guests