I decided to attempt “upgrading” my current project over to the new widgets (2.0) today. Much to my dismay, I’ve run into lots-o-trouble. The first widget in my app is a tabBar, so that’s the widget I began converting first. I was having a hard time finding the error and such, so I created a new tabBar in the most basic form I could (at least pretty close), however I ran into the same errors. These are some common things the terminal shouted at me…
WARNING: display.newImage( imageGroup, frameIndex ) given an invalid frameIndex (0). Defaulting to 1.
ERROR: bad argument #4 to display.newImageRect(): width expected, but got nil.
ERROR: bad argument #3 to display.newImageRect(): width expected, but got nil.
Runtime error ?:0: attempt to index field ‘?’ (a nil value)
Here’s the tabBar widget code…
[lua]
local tabButtons =
{
{
id = “Tab1”,
label = “Tab1”,
labelColor = { default = {0,0,0}, over = {255,255,255} },
defaultFile = “tabHome.png”,
overFile = “tabHomeD.png”,
onPress = onPress,
selected = false
},
{
id = “Tab2”,
label = “Tab2”,
labelColor = { default = {0,0,0}, over = {255,255,255} },
defaultFile = “tabSettings.png”,
overFile = “tabSettingsD.png”,
onPress = onPress,
selected = true
},
–more tabs can follow
}
local tabBar = widget.newTabBar { --------Runtime error begins here
left = 0,
top = display.contentHeight - 60,
width = 240,
height = 60,
backgroundFile = “leather.png”,
buttons = tabButtons
}
[/lua]
If anyone can offer tips, tricks, or help it would be greatly appreciated. If you need more info or if I did something stupid with the above widget let me know…
There are required images for the tabBar background. Make sure you’re providing all the required parameters. Remember the docs for this is in the Daily Builds docs, not the default public docs.
I can investigate this further tomorrow, but what I think is happening is this: because you’re specifying the “backgroundFile” parameter (and image), the TabBar expects that you’re building an entire custom visual layout using all of the pieces. So then, it’s throwing an error when you specify only “backgroundFile” and none of the other elements like “tabSelectedLeftFile” and “tabSelectedMiddleFile”.
I see how this can be restrictive and frustrating, and I’ll look into getting it fixed in an upcoming daily build so that you can specify some (or even just one) of the image elements without being required to provide all of them.
These are the visual elements which make up the “tab selected/active” state. The “left” and “right” sides are what you’d expect, and the “middle” piece spans the distance between those two, such that the tab width can be flexible and the same images can be used.
So, assume you had 3 tabs across, the “text rendition” would look like this:
There are required images for the tabBar background. Make sure you’re providing all the required parameters. Remember the docs for this is in the Daily Builds docs, not the default public docs.
I can investigate this further tomorrow, but what I think is happening is this: because you’re specifying the “backgroundFile” parameter (and image), the TabBar expects that you’re building an entire custom visual layout using all of the pieces. So then, it’s throwing an error when you specify only “backgroundFile” and none of the other elements like “tabSelectedLeftFile” and “tabSelectedMiddleFile”.
I see how this can be restrictive and frustrating, and I’ll look into getting it fixed in an upcoming daily build so that you can specify some (or even just one) of the image elements without being required to provide all of them.
These are the visual elements which make up the “tab selected/active” state. The “left” and “right” sides are what you’d expect, and the “middle” piece spans the distance between those two, such that the tab width can be flexible and the same images can be used.
So, assume you had 3 tabs across, the “text rendition” would look like this:
I’m still cannot get this to work without an error. I started with a clean slate just to work on the tabBar. Below is the tabBar code and then the error messages after that. I only used “required” commands or whatever…
-----------
ERROR: bad argument #5 to display.newImageRect(): height expected, but got number.
ERROR: bad argument #5 to display.newImageRect(): height expected, but got number.
ERROR: bad argument #5 to display.newImageRect(): height expected, but got number.
Runtime error
bad argument #2 to ‘newText’ (string expected, got nil)
stack traceback:
[C]: ?
[C]: in function ‘newText’
?: in function ‘?’
?: in function <?:580>
(tail call): ?
…53qq7ztjxw2q5kcnh0000gn/T/TemporaryItems/24/main.lua:34: in main chunk
I’m sorry for all the trouble, but I’m no pro at this and I can go no farther unless this is solved.
The one error makes it look like the label field is required (the only string I can see it using). Try passing a label to the button. If you don’t want the label just make it a space. Also the three errors:
ERROR: bad argument #5 to display.newImageRect(): height expected, but got number.
I fixed those two things and it performed smoothly! However, applying a label shifts the button off center (and I don’t want labels). Playing with the x and y offsets didn’t change anything. I can continue to work on other thing now that the tabBar is performing properly (almost), but I will need this fixed eventually.