Journey into SuperWaba

Ever wonder what it takes to write programs for your PDA? I did, and so now I am beginning a journey to try my hand at writing something for the PalmOS. SuperWaba, a variation of Java for the PDA, is my language of choice. And I'm a novice, which makes it all the more unpredictable. Hope you'll come along for the ride! Note: You can read multiple posts on one page if you click on an archive link.

Sunday, August 15, 2004

First Simple SuperWaba Program Complete!!!!

YIPPEE!!!!!!

It's been a long, long road. But finally a success. It's not much to look at, but it is a real live SuperWaba program that does something more than say "HELLO WORLD!"

Below you will find the code for a simple HiLo game along the lines of the description in the previous post. None of the bells and whistles are implemented. I don't honestly know if I'll take this any further, but for today I'm happy.

TRANSLATION: "I'm tired, and the next steps look just as hard as the previous steps, and I'm uncertain about continued success. But I'm too hooked on the adventure to stop now."

I'm a little embarrased because the code is not exactly simple and organized. But I'm also proud of it because of the simple fact that it works, and it took some work to get there. What you see is more remnants of false starts than a creation done with a single effort. In other words, it's the code equivalent of a screen door thats held together with more duck tape than screen material.

And bottom line is that I feel now like I have finished my original mission for this blog... to write a simple program in SuperWaba, and capture the journey so that others can follow with the advantage of my trials and tribulations. This blog may be wordy, but I sure wish that I had had something like this available when I started out!

LESSONS AND TRICKS: Any success like this leaves behind it a trail of lessons. Here's a few that are still fresh in my mind...
1) As noted before, you can't use a popupBlockingModal to display a MessageBox or InputDialog from the main window constructor. That is because the event handler has not been set up yet, so the program just hangs. There is a workaround posted on the FAQs, but I didn't understand how to use it, and it even seems to refer to classes that don't exist. My workaround was to move the game play code that needs popupBlockingModal into the even handler for menu items. In other words, you start a game only from a menu item. That guarantees that the event handler has already been set up.
2) There's a lot of goofy code. E.g. The whole initialization of a new game is a bit bogus and confusing because it can happen in multiple places in different manners, but it works. And the counter handling is a bit goofy also.
3) When a game finished the title bar completely disappears, so it is added again after completing a game. You can abort a game by pressing that button.
4) Custom buttons can be chosen in InputDialog by adding a String array with all the button labels in it as a 4th parameter in the constructor. When looking for the results you use getPressedButtonIndex() and compare it to the button number starting with 0. The edit text entered is found with getValue().
5) You need to use the Convert class to do basic type conversions. For example, when converting from String to int, I had to use Convert.toInt(String) instead of the Java function Integer.parseInt(String).
6) SuperWaba is NOT Java. It didn't really sink into my head how much SuperWaba is not Java until I wrote this code. It really isn't Java. There are some similarities, and the syntax is the same, but all the libraries are different. You have to learn them just like you had to learn Java libraries. And with SuperWaba there's more issues because it's more limited and because you're programming for a very limited device. This is certainly a limitation, but hey it's an open source language that is just getting started. I suspect that if it flourishes, we may find it to become more and more powerful and robust.
7) Programming isn't a whole lot easier with SuperWaba than it was with assembly coding with my Z80, or doing BASIC or Pascal. Well, yes, it is a bit nicer. But only a bit. I'm not sure whether it's because I'm not used to GUI programming or because I haven't really done real programming in so long, or because I'm just not spending the time it deserves because I'm so busy. But it's really a pain to make things work right now! Like I said before, things do get easier when you do them often and are familiar with how to go about it. Then you can concentrate more on what you are trying to accomplish rather than the elementary stuff. I still hear that call of NSBasic ringing in my ear. But hey, I already spent some big bucks on the SuperWaba tutorials (which seem more like manuals to me) so maybe I'll stick with it for a while as time allows. If I get really frustrated, I'll see if the alternative is better or worse!

Take care.
Below are some additional ideas on what a HiLo Game could include, and on my next blog post the code for my first simple program. I wanted to include it here, but seems I'm out of blog space. Hope that means this post is too long and not that the entire blog is full. That would be crazy to have happened so fast.
And as always, for those trying to learn SuperWaba, good luck!

Further ideas on HiLo gaming:
* I'm thinking now of more things that you could do with hilo guessing games. Like make it 2-d or 3-d and try to corral various animated items that prefer to escape. Once you start looking at that, it could expand into various terrains, and all kinds of special devices to gain advantage either on the hunter or the escapee side of things. AI is another possiblity instead of the target being completely random. And multiple targets could figure in. I'm sure I can come up with many more ideas than I'm willing to program!

0 Comments:

Post a Comment

<< Home