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:
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).
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.
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.
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.