Okay, I read a bunch of the Lua 5.1 Reference Manual, but then I found a different guide: Lua for Beginners. And it really is for beginners ... yay. This would not be of much use to a seasoned coder just looking for the differences between whatever language they know and Lua. But it works great for me. The guy who wrote it is German, so expect a stilted English, but mad props to him for putting this together (I think back in 2006).
So I started on page one and read. And read. Did some exercises. Read some more. And I understood more. After reading over half his "chapters" (they're very short), I went back to the Corona SDK website (I found out today that there's a difference between the Corona SDK and the Corona Game Something-or-other. Maybe they've been combined, I don't know, but I'll have to look into whether I'm using the correct stuff), and looked at some more sample apps. They actually made more sense. I'm starting to figure Lua out. Of course, after looking at several apps and their complexity I felt a bit discouraged because I'm still no where near being able to do some real coding. But ... baby steps. Tough for me because I'm so impatient (and easily discouraged).
Having emptied out my main.lua file, I created a button in it:
local bucket = display.newImage( "bucket.png", 45, 20 )
Okay, actually, I displayed a PNG graphic. But it's also my button. After learning more about events today, I made the button turn on its side when you click it:
local bucket = display.newImage( "bucket.png", 45, 20 )
local function turnBucket( event )
bucket:removeSelf( )
display.newImage( "bucket_pour.png", 45, 20 )
end
bucket:addEventListener( "touch", turnBucket )
So what did I learn today (besides this?). Well I learned that "touch" is an event name reserved by Corona to indicate that someone has touched the screen of their mobile device. Before today I didn't know if "touch" was a user-defined variable like bucket or turnBucket above. I also found where a bunch (or maybe all) of these Corona-defined events are listed.
What I didn't learn was why the word "event" is between the parens after turnBucket. The chunk of code above worked with the word "event" and without it. I shall go do some exploring and see if I can find the answer.
Second only to learning to code, is learning where all of the resources are. The more I look, however, the more confident I feel that all the information I need is out there ... I just gotta find it.
No comments:
Post a Comment