Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview

Buy Now

Issue 8.1


Karel the REALbasic Robot

How the rbKarel robot simulation teaches logic with RBScript

Issue: 8.1 (November/December 2009)
Author: Andy Dent
Author Bio: Andy is a freelance developer from Perth, Western Australia who alternates REALbasic with C++, C#, Ruby, and Objective-C and welcomes the return to the kindler, gentler and often more-productive world of REALbasic.
Article Description: No description available.
Article Length (in bytes): 36,455
Starting Page Number: 30
Article Number: 8110
Resource File(s):

Download Icon project8110.zip Updated: 2009-11-02 11:51:29

Related Web Link(s):


Excerpt of article text...

Karel the Robot has been around for nearly thirty years as a way to teach people the basics of logic through solving simple problems. The rbKarel project uses RBScript to provide the language interpreter for Karel along with a few goodies like spoken output and single-stepping. It also uses a much simpler context object for a second RBScript to define worlds. Why write a parser when RBScript does the hard work for you? This article doesn't attempt to teach the basics of RBScript -- see the resources list at the end for past RBDeveloper articles on that topic. What I do cover are some of the interesting challenges in adapting RBScript for Karel and particularly how to add single-stepping and other controls over the script execution. As I wrote the article I also found myself explaining a few points about the software design decisions, which may seem heavy-handed to experienced programmers but hopefully will keep reminding others of some core principles.

When Jeff Ayling posted his request for help, I was intrigued by the "Just how hard could it be?" prospect of trying to implement a particularly REALbasic style of Karel.

I had already published a complex example of RBScript being used to drive 2D graphics. Putting a little user logic on top of this didn't seem that hard, just a case of adding a few methods to the context object to manipulate a robot. Things are never quite as simple as they seem in the first rush of enthusiasm and one challenge I hadn't anticipated is that Karel's world is not one of pixel coordinates but of a grid with intervening walls and coordinates. The first public teaching trial also proved that adding single-stepping and some feedback as to what was going to happen next was a hugely desirable feature.

Karel From the Users's Viewpoint

Karel moves around on a simple grid of vertical Avenues and horizontal Streets, with walls between. See Figures 1 and 2 for examples. He carries a Beeper Bag into which he can put the Beepers he picks up and from which he takes beepers to put on the grid points. Beepers are conceptually there -- they are visible but (thankfully) do not actually beep. Real audible beeping is not an enhancement that has been requested and is probably the Karel equivalent of the <BLINK> tag. If more than one beeper is on a given grid location, we have improved visual feedback that a count is visible in the middle of the beeper.

...End of Excerpt. Please purchase the magazine to read the full article.