Beware the widget

The Jabberwock, as illustrated by John Tenniel

 “Beware the Jabberwock, my son!

The jaws that bite, the claws that catch!

 Beware the Jubjub bird, and shun The frumious Bandersnatch!”

 So, I wanted a simple drop down list so a tester/player could pick a scene and then go there.  I didn’t find what I wanted, but there was this nice feature of the Corona Widget object library called the newTableView:

 Corona tableView widget

Looks good, maybe more complicated than what I need but the code looks straight forward (okay, not as easy and straight forward as old school classic VB 6 – but not as weird and hard as Visual C++ MFC of the same era – and once again I’m dating myself…)

The demo’s I found here and here provided the basics – but!  I need to incorporate this inside the Corona Storyboard construct.  And that is where the fun and games began…

Now a mea maxima culpa is in order – what follows is probably due to my being overzealous in getting rid of memory issues.

I created two arrays – one is a straight forward array with the names of the scenes in order that I want to provide.

The second is an array of arrays used by the tableView object.  One of the weaknesses in using Corona is the documentation is sparse and terse – just enough to get you into trouble – but the stuff you really need to know is found in the forums. From what I’ve figured out is the row construct in the list allows you to have a picture object, a title and then descriptive text. There may be more, but this is far more at this point than what I really need.  Hence an array of arrays – or to use the Lua way of thinking – a table with individual rows that could contain a number of fields (columns) greater than one.  Let’s move on.

 He took his vorpal sword in hand:

Long time the manxome foe he sought—

So rested he by the Tumtum tree,

And stood awhile in thought.

 Got my lists, got my tableView, and wow – it actually displays what I want!

It’s just that the damn thing crashes when I do a selection.  This one got me.

And as in uffish thought he stood,

The Jabberwock, with eyes of flame,

Came whiffling through the tulgey wood,

And burbled as it came!

So I unsheathed my vorpal sword – er, I started to really use the Lua Glider debugger.  Need to go back a bit here.  In my desire not to create any more memory leaks I had made sure in the storyboard function scene:exitScene I set any variable I declared to nil.  And that was the source of my errors.

One, two! One, two! and through and through

The vorpal blade went snicker-snack!

He left it dead, and with its head He went galumphing back.

The errors were just – weird.  Didn’t make sense.  And here is where using Lua Glider saved the day (used as my vorpal blade).  I set a break point for the listener function in my code – the code that gets fired when a user clicks on a selection in the list.

And as I expected the code worked perfectly – selecting the correct item in the selection array based off the event index.  But then we went down the rabbit hole…

It turns out after all of that the storyboard code kicked in.  The exitScene code got called – setting all of my variable to nil.  Oh – and then the listener function got called again – and since everything had just been set to nil it set off errors – oh my…

Okay, I’m sure my code isn’t the most efficient at this point.  Why the listener function is getting called twice I can’t answer.  However I did learn a valuable lesson here.

“And hast thou slain the Jabberwock?

Come to my arms, my beamish boy!

O frabjous day! Callooh! Callay!” He chortled in his joy.

 ‘Twas brillig, and the slithy toves

Did gyre and gimble in the wabe;

All mimsy were the borogoves,

And the mome raths outgrabe.

Clearly, at this point in my Lua/Corona development the ONLY stuff I should be setting to nil (null) in the storyboard scene:exitScene function are those objects that get inserted into the display view/self view group.  Anything else – well as the maps used to say here be dragons

Cross posted at my other blog SE Studio Team C


Been busy at my other Blog site

I noticed I haven’t posted at this site in a while, I’ve been busy with several projects and writing at another blog site.

Since last September I’ve been working with a small team creating a cross-platform game using Corona SDK.  We’ve called our project Flights of Fancy, and we’re doing weekly write ups here.

Corona SDK uses Lua as the scripting language – I find it very much like classic VB.  Easy to get into which means you can write a lot of bad code – but capable of doing some elegant programming.

One interesting aspect of our group – we’ve never met in person.  And we are spread out across the US; one of us on the east coast, one on the west coast and the rest spread in the mid-west.  We use Skype, Google products, Trello and Mantis BT to keep everything on track.

%d bloggers like this: