Menu script

Things go as they do and often they follow the same process. I start something and suddenly find myself writing version after version of one and the same function because I keep finding ways or reasons how to do it better. Or because I simply like the challenge. The Celestia menu stuff turns out to be no exception.

Initially I wrote the spacecraft script that needed a menu of some sort. When the script was done I extracted a simple version of the menu-code for later use in future scripts. Much easier to do it immediately when I still know what I have been up to. Like the menu in the spacecraft script this extract:

had one shortcoming: by design it could not deal with [Ctrl]+[Key] combinations. This is because I didn't find out until later that these combinations actually wére reported, but as a three-character code per keypress instead of the one-character code that the script was based on. This information is not available in the Celestia documentation for the key-event; I just happened to stumble across a [Ctrl]+[Key] example in some script example on the forum. For details see Key event.

Since the menu-script was still fresh in my mind I decided to upgrade the example script to a version that cóuld deal with [Ctrl]+[Key] combinations. It turned out to be less simple a change then I had thought because of some pert lua qualities that I have recorded here. That version became:

But working to change the script I started wondering if it would not be a better idea to make an object oriented version of the menu. Something that I don't have to rewrite everytime but that I can put in a celx-library and reuse whenever I want to. The working but not yet definite result is:

And it still doesn't stop here, since my mind is already playing with the idea how to make an object version where I can add a menu-object to a second menu-object and have it function as a submenu. My mind sometimes simply has a mind of it's own and likes small challenges like this one, so the nex stop on this page possibly will be:

    • Celx submenu Object

but probably not in the very near future.