Hello,
My name is Kes and I’ve recently started watching tutorials on how to create apps with Corona and I think the package is awesome so far. I’m very new to coding anything as I’m more of an Concept art assets guy. I’ve been picking up Lua pretty well so far with functions, tables etc. however I’m getting stuck on this if then statement,
Seems not matter what I do I always get “Nil” as my answer for age instead of the actual number. When I copy the tutorial’s code it works perfectly. Yet when I insert my own code it doesn’t seem to work even though it seems like I’m following the formula perfectly. I’d appreciate some fresh eyes to take a look at my code and help me figure out where I’m going wrong so that I end up with “nil” constantly.
Thank’s in advance for the help!
Here’s my code:
local zombie1= {name="Bob", age="10"}local zombie2= {name="Sam", age="20"} local Creatures= {zombie1, zombie2} local function getAge(n) for idx=1, #Creatures do if Creatures[idx].name == n then age = Creatures[idx].age break end end return age end print(getAge("zombie1"))