FAQ Wednesday

Share on Facebook0Share on Google+0Tweet about this on TwitterShare on LinkedIn0

This is a new series of blog posts that will appear every Wednesday and covers five frequently asked questions (FAQ) from support cases, the forum, and documentation comments. Hopefully there will be something here for both the experienced Corona users and those using Corona for the first time.

So let’s get started.

Question 1

I can see my “print” messages in the Corona terminal when running the Corona simulator but I don’t see the messages when I’m running on the Xcode iOS simulator or my device. What am I doing wrong?


If you are testing iOS devices and loading the app using Xcode, the Xcode console will display the print messages. If you are using the Xcode iOS Simulator, start Mac’s console app and you will see the messages there. If you are testing Android devices, you should download the Android SDK and use “adb logcat” to view print messages (and other device messages).

Tip: I f you don’t see your messages coming out in a prompt manner, add the following to the top of your main.lua file:

Question 2

I’m confused about setting the x and y position of display objects. Are the values I use when I create the object the same after it’s created?


For most objects, the x and y position is defined as the “top-left” location when the object is created and changes to the center of the object after it’s created. The exceptions are display.newCircle, display.newLine, and display.newGroup. The display.newCircle object is created by specifying the center of the circle and display.newLine uses the start and end points of the line segment. The display.newGroup is created by defining the top-left point and the x and y reference point doesn’t change after creation. All other display objects use a center reference point after the object is created. This means changing the x and/or y parameter of the display object will translate (move) the object relative to the center of the object. The object:setReferencePoint API can be used to change a display object reference point after creation.

To avoid this confusion, some programmers create objects using 0, 0 for the top-left location and then set the object’s x and y value after the object is created. This means all the x/y positioning for objects are based on the center of the object (unless the reference point is changed).

Question 3

When I have multiple touch objects, I see the touch event on multiple objects when they overlap each other on the screen. How do I stop that from happening?


The dispatch code for touch (and other) listeners call the top-most object where the touch event occurred. If the listener returns “true”, the event dispatcher stops the touch event. If the listener returns “false”, the dispatcher looks for the next object with a touch listener that is under the touch area (or Runtime listener, if it exists). This continues until no more touch listeners are found or until a listener returns true. The common mistake is not returning a value from the touch listener. If no return value is specified, the default value is “false.” The bottom line is always add a “return true” statement at the end of your listener code unless you want to pass the touch event to the next object.

Question 4

I’m getting build errors saying the code signing was wrong or invalid entitlements. What can cause this?


If you get build errors on your app and it’s not related to syntax errors in your code, try removing/renaming the build.settings file to see if the error goes away. If there is no error without the build.settings file, look for something wrong in the file. You can also try building one of the Corona sample apps (e.g., “Hello World”), to rule out anything wrong with your project. Also try changing the name in the Application Name field to a simple name like “test”, to rule out any issues with invalid characters causing problems.

Question 5

I’m using “require” to load my Lua code from a subdirectory and it works in the Corona Simulator but my app crashes when I run it on my device. Does Corona support loading code from subdirectories?


Yes, you can place your Lua code in subdirectories but you need to be careful because of the slight differences between the Corona Simulator and running on a device. First off, make sure the file name in your “require” statement matches the actual file name. The common error is using “require(“Testlib”)” when the file is actually “testlib“. The Corona Simulator will accept it ether way but the device will not.

The second issue is how you specify the subdirectory. The correct way is to use period (“.”), between the directory name and the file name. If your library file is “test.lua” and it’s in the “library” subdirectory, you would call it like this:
test = require( "library.test" )

The Corona Simulator allows the directory separator to be specified using slash (“/”) as well as the period, but the file will fail to load on the device. Always use period to separate the directory name from the file name. As you have probably guessed, your lua file names cannot contain any periods in the name expect for the “.lua” extension.

One additional point. Sometimes you see the “require” statement without the parentheses. This is valid lua code as long as there is only one function parameter and it’s either a string or table. So the following is same as the code above:
test = require "library.test"

That’s it for today’s FAQ and I hope you learned something new. If you have questions please post them in the forums for all to see and comment. You can post short comments here but I urge everyone to use the forums.

Share on Facebook0Share on Google+0Tweet about this on TwitterShare on LinkedIn0

This entry has 19 replies

  1. Michael says:

    Thanks! Questions are really interesting and answers are clear. Waiting for the next wednesday 🙂

  2. Cool thanks! I didn’t know about the (.) dot separator. Big help 🙂

  3. Jonathan Beebe says:

    Great article Tom! This should clear up a lot of confusion for many developers.

    Regarding the question about overlapping touches, for those who want more information, here’s a link to a recent tutorial that goes more in-depth on the subject:

    Tutorial: Detecting Touches in Corona

  4. Joakim says:

    One more topic for the next FAQ.

    Difference between touch and tap event. How to code for all different of multi touches and distinct between them in the same event. For example, touch, double touch, and swipe in the same listener. Logic for handling one of the listed events and not trigger the other. I have been struggling with this from time to time, and haven’t famed up with a good solution yet.

  5. Joakim says:

    “haven’t famed up” should be “haven’t camed up” 😉


  6. OH SNAP!!! The “.” separator is the cause of all my woes this last week when trying to deploy to my Kindle Fire!!!! Can’t wait to see if that solves my issue!!!

    Thanks so much for a great article!!

  7. Nate Johnson says:

    Something that I think would be really great is if the simulator would not run your app if you did something that would not run on the device. That way people would not have to find out later and bug hunt if they had incorrect character case, path separators, etc.

    If that could be added, it would make Corona that much better, IMO.

  8. Naomi says:

    Thank you for posting this.

    About the “.” separator, you noted that using slash (“/”) is allowed on Simulator but will fail on device. I’m a bit confused by this. I use slash (“/”) for PNG files directory, and I’ve been using display.newImageRect( “PNG/myImage.png”, width, height ) throughout my game — and it causes no problem on both iOS and Android devices.

    Am I hearing that “.” separator must be used if we place .lua file inside a subdirectory, but if it’s image, it can use either “.” or “/” for the time being? Am I hearing that the use of slash will be deprecated over time? Or with images, the use of slash will remain permissible without fail moving forward?

    Also, what about sound files. When I started learning Corona back in July 2011, I remember reading something about audio files needing to be placed in root directory (because of some problem with some device — could’ve been Android, but not sure.) If we can place audio files inside a subdirectory now, must we use “.” or “/” (or either?)

    I could search and replace all “PNG/” with “PNG.”, and I could also move all of my audio files to audio subdirectory (which will make the switching between Android ogg files and iOS acc files so much easier.) But before I take these steps, I’d like to know where we stand on the use of “.” and “/” for the subdirectory a little more.

    Thanks again.


  9. Tom Newman says:

    @Nate, The goal is to make the Simulator work the same as the device but sometimes that’s not entirely possible because OS differences. The way file names are handled is one of those areas.

    @Naomi, the use of “.” is only for loading Lua files from subdirectories. For your asset files (PNGs, JPGs, MP3s, etc.), you still use “/”.

    Loading asset files from a subdirectory on Android was a an issue in previous builds but that has been fixed.

  10. Naomi says:

    Tom, thank you for the clarification!


  11. Michael says:

    Hi Tom! Could you clarify the second question. I make a build for XCode Simulator from the Corona Simulator. After the build is done, the XCode Simulator window is opens and I want to see if there any errors or print output. But I have no output in Corona Terminal, and when I open Mac’s Terminal (hope you mean this, when you say “Mac’s console app”), there is no output too. I already add that line io.output():setvbuf(‘no’) but still no success.

    What am I doing wrong?

  12. Tom Newman says:

    @Michael, do a Spotlight search for “console”. You want to open console.app. You will find the Xcode simulator output there.

  13. Mo says:

    GREAT start Tom! Love the simple explanations. Would it possible at some point to gather all future faq’s into it’s own page we won’t have to hunt the blog for all FAQ Wednesday blog post?

    Thank you for this new feature. Very helpful.


  14. Michael says:

    Hey, Tom!

    Thanks, my bad, wrong app 🙂

  15. Michael says:

    I do find the console and see some messages when build is preparing, but still not see print statements. I got system messages from Xcode Simulator, like when I kill the app, but there is no print output or any errors from my app. Even if I made the print command the first line of my code.

    What can it be?

  16. Michael says:

    Figured it out. Needed to enable Senders in the bottom window of console.

    Sorry for fuss and thanks again!

  17. Natalie says:

    I have downloaded the Corona Labs however my version does not have the terminal folder and i am getting frustrated because i have looked for it everywhere any suggestions on where it could be or how to get it. Using windows.

    Many thanks

  18. Shavon says:

    When building in corona, you have the iOS simulator and corona simulator, how do you display your app on the iOS simulator? just the part that user would click on to open your app.

  19. Raman says:

    in android device the build not working properly it get crashed and closes the game with sound ,but without sound its works fine.what would be the issue