Lets supose i have this:
local itens = {sword = 2, shield = 3}
and supose that I don't know the content of this table, so I want to print its names without its values, like this
sword
shield
how should I do it?
Lets supose i have this:
local itens = {sword = 2, shield = 3}
and supose that I don't know the content of this table, so I want to print its names without its values, like this
sword
shield
how should I do it?
Hey there!
The only method of getting the name of the key in the dictionary that I know of is using a for loop.
Example:
local items = {sword = 2, shield = 3}
for i,v in pairs(items) do
print(i)
end
However, this will not print in order as dictionaries don't have an order. So the output will either be
--sword
--shield
or
--shield
--sword
#Do
print(itens.sword) -- 2
Apologies for lack of elaborate answer.
You can print by using itens[Numberhere] , for example:
print(itens[1])
It would print 2 (or shield idk)
oh wait it print nil .........In order to use it u have to remove =1 and =2 then u can use if statement
This discussion is preserved as it was. New answers, comments, and votes are closed.
5 comments
Are you kidding me... (me dunno how to do it either lol)
ikr, and ALSO REMOVE THE MODERATION ON MY QUESTION >:( xD
why cant i take anything serious.
heey, i want it to print the key name, not the value inside it.
Oh, apologies I'm not sure how to do that, i think you need metatables to do that task then.