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.

Saturday, August 14, 2004

A Couple of SuperWaba "Gotchas"

As promised, here is some further information about some of the problems I ran into when trying to code a HiLo Guessing game.

1) Like with every new language learned, I'm spending a lot of time trying to "get my bearings" and figure out what pieces available, what are needed and what goes where, etc.
2) The popupBlockingModal() command, used to display a message box or input dialog cannot be used in the main constructor or the onStart() method of the Main Window. The workaround is probably clear to a Java-whiz, or to a pro with SuperWaba, but to me it is going to take a little more study to understand how to make it work.

The approach I decided on for my first attempt at a simple HiLo game was to put things like "New Game" in the menu, and the constructor would hold most of the generic setup, and a playGame() method would intialize the game members (variables), which are basically all going to be static. That means that regardless of where they are referred to within this single class program, they are the same variable. It is implemented that way by defining the static variable in the class definition before the contructor method. Then, I think, even if a new object is created and assigned to that static variable from inside of a method, the object value of the variable is available anywhere in any method of the class. (Note: Upon reflection, static variables were not needed, just the location of the variable definitions outside the methods of the class, so it's accessible anywhere inside the object. Doesn't really matter for this app, I think, whether they are static or not.)

My plan was to handle the main game activity by a series of InputDialog boxes. A new one pops up every time a guess is entered. It contains text that indicates what the last guess was, how many guesses have been made, and whether the last guess was too high, too low or correct.

The user then has the choice to enter a new guess or abort the game. If the guess was correct, a new secret number is selected and the first guess is requested. If the user is done, he just the abort button.

Note: This technique of handling game endings is one way to make a simple game addictive. If the next game is already started up, it "invites" you to continue one more time rather than abort. It's especially enticing if there is some sort of cumulative scoring that includes multiple games. I noticed this first when playing a solitaire game that's set up this way. It was hard to put down. Eventually, after leaving permanent marks on my touch screen and wasting way too many hours playing, I was forced to remove it from my Palm!

BTW, I have all kinds of ideas for future versions if I don't get fed up with SuperWaba first. For example:
*) Allow guessing with alphanumeric guesses and using lexicographical ordering
*) Allow guessing numbers in different bases, such as hexadecimal
*) Allow random movement of the secret target between each guess, and with specified ranges and probabilities.
*) A progress bar that graphically indicates the min/max values, and the remaining hi-lo range of possible target values based on previous guesses and potential movement of the target.

I think this makes for an interesting programming exercise that would include some graphics, but isn't really going to require too much out of me.

An aside: To be honest, all the overhead required to do simple things is making me a little less thrilled with SuperWaba as a hobby language. I'm sure it's speed and power is an advantage relative to alternatives like NSBasic, but as someone with little spare time, it just doesn't seem like the best choice for me right now. In High School, this would have been the ultimate joy, especially compared to the languages and computer hardware that was available to me at the time. But in those days I had the luxury of devoting a lot of time on these things. Currently, I have to be careful with my time, and am already using too much of it on this! But like I keep saying, time will tell. Sometimes things that sound hard at first turn out to be pretty simple once you learn what you're doing. Especially if you are using something all the time.

Have I mentioned recently that I really appreciate Daniel Tauschke's MobileCreator IDE? It's great! While it may make sense to switch to the open source Eclipse IDE (it's well-known in the Java world also, so it might be something with more general application), I really like the integration and simplicity that MobileCreator provides. And I appreciate his making it available in a free starter version appropriate for hobbiests. If I were to ever get serious with SuperWaba, I'd have to consider his professional version very seriously just because I like his product and would like to support his work. And some really exciting news... he is apparently going to be adding a GUI builder into either his IDE or Eclipse. That's based on a newsgroup posting and not official yet, but I'm sure looking forward to seeing what he has coming!

So, anyway, now that you know my plan, let me briefly indicate the struggles so far. Number 1 is just as to be expected. New language, new issues, hard to tell how to go about doing some simple things. And often even after making these things work, it's hard to remember exactly what was involved because I got to the solution in such a roundabout and incremental way through trial and error.

Number 2 refers to something that is posted under the SuperWaba Wiki FAQs...

Why does using popupBlockingModal() to show a MessageBox? in onStart() hang?

The window that you are trying to pop the MessageBox? up on top of is not ready yet.

To get round this, use a Container to hold the code that wishes to do a popupBlockingModal, and do Window.getTopMost().popupBlockingWindow() from within it. This will work in the onStart() method of the Container because you create the main Window before the Container is initialised. This is an example of the use of Swap to load a container from a main Window class:

   public void onStart() {

/* Now we get our client rect, excluding the border and the title */
Rect r = getClientRect();
/* Prepare the splash screen. */
splash=new SplashScreen(); // A Container
/* Swap in the SplashScreen module. */


I'm not exactly sure how I'm going to make this work yet, so there's some more experimentation and learning to do. That one-hour iziBasic program I wrote keeps running though my mind... it was so easy!

Hope to have some answers next time, or at least a workaround.
Until then, if you are trying SuperWaba yourself, good luck.
And if you're a SuperWaba expert, how about some help in the comment section?!

As my some of my online associates say... Cheers!


Post a Comment

<< Home