Chapter 3 - Bringing it to Life

Hi all, 

I’m working on Star Explorer app in the Introduction to Corona and for some reason the asteroid is stuck in the upper left corner of the tablet.  The odd thing is when I turn the last line the gameLoopTimer into a comment there are no problems, ship moves side to side and gun fires.

I checked the config and the build, I did receive a syntax error, but then it disappeared.  I really at a lost.  

Appreciate any help, 

Thanks

You are likely getting an error. Look in your console log that should be opening behind the simulator. Notice the two Corona Icons in the task bar? The Console log window is one of those two, the simulator the other.

Rob

I’m going out of my mind I can’t figure out where the error is, I even tried by copying and pasting the codes directly from the corona site, but even that didn’t work.

I’m trying to learn this, but it’s so confusing at times but I won’t give up.

Appreciate any help, 

Thanks

As the error in the console shows, one of your functions is missing it’s ‘end’ statement.

I deleted almost all the code and started again, fortunately I was able to locate the missing _end _statement.

Thanks for helping me.

Missing end statements should be one of the easiest things to find, if your code is indented properly. Looking at the first screenshot everything looks okay, but if you look at the second screenshot an indention error was leading you to trouble.

Look at the line:   local whereFrom = math.random(3)

It is indented properly but just below it the “if” statement is tabbed to the left a level. Since that whole block is shifted to where it looks like it lines up with the function declaration, the last end looks like it ends the function. Had that if block been indented one more level, you would have easily seen where the missing end was.

Parring up block beginning and endings is one of the most frustrating things to new programmers. Even experienced developers can get frustrated by them too. But being disciplined with your code formatting is a great way to avoid a lot of common pitfalls.

Rob

I don’t bother with this unless I’ve got about 12 nested if/thens (too lazy :D) but some programmers where I work also comment each ‘end’ statement with something to identify the code block it is closing. Makes it slightly easier to identify a missing or extra ‘end’…but sometimes life’s too short!

Great suggestion Nick. I don’t do it much with Lua because I’m really strict with my indentions and I try to avoid a lot of nesting. But with HTML and closing </div> tags, there can be significant nesting and frequent single line <div></div> pairs and commenting the ending </div> can be a real life saver.

That practice, particularly for people new to programming and new to Lua is an awesome thing to add to your “toolkit”.

Rob

You are likely getting an error. Look in your console log that should be opening behind the simulator. Notice the two Corona Icons in the task bar? The Console log window is one of those two, the simulator the other.

Rob

I’m going out of my mind I can’t figure out where the error is, I even tried by copying and pasting the codes directly from the corona site, but even that didn’t work.

I’m trying to learn this, but it’s so confusing at times but I won’t give up.

Appreciate any help, 

Thanks

As the error in the console shows, one of your functions is missing it’s ‘end’ statement.

I deleted almost all the code and started again, fortunately I was able to locate the missing _end _statement.

Thanks for helping me.

Missing end statements should be one of the easiest things to find, if your code is indented properly. Looking at the first screenshot everything looks okay, but if you look at the second screenshot an indention error was leading you to trouble.

Look at the line:   local whereFrom = math.random(3)

It is indented properly but just below it the “if” statement is tabbed to the left a level. Since that whole block is shifted to where it looks like it lines up with the function declaration, the last end looks like it ends the function. Had that if block been indented one more level, you would have easily seen where the missing end was.

Parring up block beginning and endings is one of the most frustrating things to new programmers. Even experienced developers can get frustrated by them too. But being disciplined with your code formatting is a great way to avoid a lot of common pitfalls.

Rob

I don’t bother with this unless I’ve got about 12 nested if/thens (too lazy :D) but some programmers where I work also comment each ‘end’ statement with something to identify the code block it is closing. Makes it slightly easier to identify a missing or extra ‘end’…but sometimes life’s too short!

Great suggestion Nick. I don’t do it much with Lua because I’m really strict with my indentions and I try to avoid a lot of nesting. But with HTML and closing </div> tags, there can be significant nesting and frequent single line <div></div> pairs and commenting the ending </div> can be a real life saver.

That practice, particularly for people new to programming and new to Lua is an awesome thing to add to your “toolkit”.

Rob