Hi,
I’ve created a newSpinner, but it just won’t spin! Here is my code (straight from the documentation)…
local spinnerDefault = widget.newSpinner { left = 100, top = 100, }
Hi,
I’ve created a newSpinner, but it just won’t spin! Here is my code (straight from the documentation)…
local spinnerDefault = widget.newSpinner { left = 100, top = 100, }
try this. most widget examples leave off the ( )
local spinnerDefault = widget.newSpinner ({ left = 100, top = 100, })
.
I’m pretty sure the ( ) isn’t required in those cases. In every case I’ve seen (and tried) it works without them, just the table itself. (Although it seems “odd” and may be anti-best practices.)
Jay
Since it’s a function how are they avoiding it
Magic? I dunno, but it’s like that in all (?) the widget examples and they all work just fine that way.
The button example is almost stand-alone:
http://docs.coronalabs.com/api/library/widget/newButton.html
Copy that example and delete the two lines inside newButton that call for graphics and run that. It’ll work without the parenthesis.
Jay
[Edit: Of course, it will also work with the parens as long as the opening one is on the same line as newButton.]
I think you have to start and stop the spinner in your code. Try adding this line.
spinnerDefault:start()
And on the topic of the missing (), it’s OK to omit them in this case. It’s a syntactic sugar feature of Lua that if the only argument you pass to a function is a new table, then you can omit the () and go straight to the {}. See section 2.5.8 here: http://www.lua.org/manual/5.1/manual.html.
Looks like start() does the trick - can’t believe that is undocumented!
Looks like it’s documented here: http://docs.coronalabs.com/api/type/SpinnerWidget/index.html. But admittedly it’s a little hard to get to this page from the page on widget.newSpinner().
Ahh - good pickup - I only looked at http://docs.coronalabs.com/api/library/widget/newSpinner.html - would be nice to have a Gotcha on that page to link the two, or have the sample code at the bottom actually include it so it runs correctly!
Nathan.
Forgot all about sugar. However I don’t think it should be used in examples in the docs. It could be confusing to beginners as it was to me
Forgot all about sugar. However I don’t think it should be used in examples in the docs. It could be confusing to beginners as it was to me
I think you’re right about the official examples. And while I’ve been doing it the “shorthand” way in my examples, I’m going to quit and add the parens. It makes more sense to keep things equal, I think.
Jay
try this. most widget examples leave off the ( )
local spinnerDefault = widget.newSpinner ({ left = 100, top = 100, })
.
I’m pretty sure the ( ) isn’t required in those cases. In every case I’ve seen (and tried) it works without them, just the table itself. (Although it seems “odd” and may be anti-best practices.)
Jay
Since it’s a function how are they avoiding it
Magic? I dunno, but it’s like that in all (?) the widget examples and they all work just fine that way.
The button example is almost stand-alone:
http://docs.coronalabs.com/api/library/widget/newButton.html
Copy that example and delete the two lines inside newButton that call for graphics and run that. It’ll work without the parenthesis.
Jay
[Edit: Of course, it will also work with the parens as long as the opening one is on the same line as newButton.]
I think you have to start and stop the spinner in your code. Try adding this line.
spinnerDefault:start()