Basic lua question

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
noatom
Prole
Posts: 10
Joined: Sun Feb 17, 2013 9:51 pm

Basic lua question

Post by noatom »

If I have this:

Code: Select all

t[2] = { "apple", "pear", "banana" }
how should I acces pear? t[2][2] or t[2].pear? Could I do this: t[2][2] = { "inception" } ?

And most importantly,what would happen if i'd run a loop to go through t? what would it output when it got to t[2]? cause t[2] has 3 elements!
spectralcanine
Citizen
Posts: 65
Joined: Sat Dec 22, 2012 8:17 am

Re: Basic lua question

Post by spectralcanine »

Why not try it out?

print(t[2][2]) -- hint: it will print "pear"

Why does it matter in a loop that one of the elements is another table? you can use tables anywhere you want.
User avatar
Qcode
Party member
Posts: 170
Joined: Tue Jan 10, 2012 1:35 am

Re: Basic lua question

Post by Qcode »

If you wanted it to print t[2].pear then you would have to do

Code: Select all

t[2] = {apple = "apple", pear = "pear", banana = "banana"}
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest