If you’ve not heard much from this quarter, its because I’ve been keeping busy.

First, I’m in Portugal, at the windy, south-western most point in Europe.

Beach
I actually spent more time jogging here than sunning and relaxing…

 

Windy-Shores
Carrie nearly blew away from the end of the world!

Most of my last few weeks has been spent bootstrapping 42. You can find out more about that on the newly revamped Transterpreter site. We’ll have a complete source download shortly. (It turns out I had broken the build in the trial release we did… mercy.)

Back to Canterbury tomorrow.

Who are we to implement a programming language?! Truly, there is barely a more offensive act of hubris in the world of computing.

42 is intended to be a platform for exploring parallel code generation and distribution. Furthermore, it is an experiment in compiler implementation; we are attempting to implement a safe, yet extensible framework for extending and maintaining our language. So far, we are incredibly pleased with our efforts, but time will tell.

More information will make its way here in due time; for now, you may be interested in our project pages in the Transterpreter wiki:

http://www.transterpreter.org/wiki/42

As we’re likely to take Monday off, it might be interesting to see the size of the project; the compiler remains delightfully small at 3123 lines of Scheme! What is also fun about sloccount is that it gives you estimated development times and costs. We began our work on July 6th, 2006, and sit at July 23rd, 2006. So, by some unknown metric, there has been over one year’s worth of work carried out, worth roughly $150,000.

If only.

SLOC    Directory       SLOC-by-Language (Sorted)
3123    top_dir         lisp=3123
1289    tests           soccam=1045,lisp=244
473     macros          lisp=473
179     docu            lisp=179
90      drscheme        lisp=90
8       scripts         lisp=8

Totals grouped by language (dominant language first):
lisp:          4117 (79.76%)
soccam:        1045 (20.24%)

Total Source Lines of Code (SLOC) = 5,162

Dev Effort Estimate, Years        = 1.12
 (Basic COCOMO, Months = 2.4 * (KSLOC**1.05))

Schedule Estimate, Years          = 0.56
 (Basic COCOMO, Months = 2.5 * (mths**0.38))

Est. Num. of Developers           = 2.00
 (Effort/Schedule)

Total Estimated Cost to Develop   = $ 151,391
 (average salary = $56,286/year,
  overhead = 2.40).

SLOCCount, Copyright (C) 2001-2004 David A. Wheeler
SLOCCount is Open Source Software/Free Software,
licensed under the GNU GPL. SLOCCount comes with
ABSOLUTELY NO WARRANTY, and you are welcome to
redistribute it under certain conditions as specified
by the GNU GPL license;see the documentation for details.
Please credit this data as "generated using
David A. Wheeler's 'SLOCCount'."

I need to be better about posting regular updates. If we’re going to have a blog, I should use it.

Website and source code

First, we’ve moved to MediaWiki for our main website. This was a large change, and hopefully it means more documentation will find its way more readily to the WWW. If nothing else, it means Damian will be able to edit pages related to projects he works on, since the old system was very, very scary, and very, very ugly. (I thought the old system would be a good idea! My bad!)

Second, source will soon be available via anonymous SVN. We have one or two more things to put into place, but will be making source code available shortly. (If you can’t wait, send me an email at matt at transterpreter dot org.) Tied into this is our switch from Mantis to Trac for project management. You can view

http://trac.transterpreter.org/

which lets you view the source to the Transterpreter, skroc, and slinker, as well as submit bugs and whatnot. We’ll make a Subversion checkout URL available shortly.

42, a compiler for …

Third, we’ve begun work on a new compiler for an oocam-like language. The existing compiler is too large and monolithic to consider extending, and the up-and-coming NOCC is already 50,000 lines of C. I’ve already said my peace on the foolishness of writing a compiler in C, so I’ll move along swiftly.

Our goal is for our compiler to be extensible, first and foremost. To do interesting research in areas surrounding concurrent programming languages, we’re going to need a platform upon which to experiment and test ideas. Furthermore, I want it to be a platform that undergraduates who are interested in doing research can contribute to in meaningful ways. So, we’ve started from scratch with a subset of occam; we’re calling the compiler 42.

I’ll probably show similar pictures again in the future, but I wanted to show a few syntax errors that the compiler generates so far. You see, I’m a bit picky about syntax errors, and if we do our job right, this compiler will have better syntax errors than any other compiler for any other language out there.

42-instance-undefined

An undefined process instance

If you’re trying to call a pre-defined process, the question is: is it defined? This is much like trying to invoke a method in Java that hasn’t been defined, or calling a function in Haskell that you hadn’t yet actually written the code for. Currently, we just say 'process-name' not defined; in my book, this isn’t enough. And since the compiler is written in a micro-pass style (very much like the Indiana nanopass style (PDF)), I can improve this error while writing this post.

One file is responsible for this check, and it is called check-instances-exist.scm. I can open it up and improve the message very simply. I like the improved error a great deal more.

42-instance-undefined-new
An improved, undefined process instance message

That took one minute. Perhaps less. Now, instead of just saying 'bar' is undefined, the message says

instance:not-defined:
	'bar' is not defined. For it to be defined
	you must have something that looks like

		 (proc bar (...) ...)

	in your code, where the '...'s might be filled
	in with code you write yourself.

 in: (seq (:= x 4) (foo x) (bar))

Along with this message, the relevant code is highlighted, so the user can see exactly where their syntax error took place. (To do this, I’m leveraging the excellent and extensible DrScheme programming environment, which was designed to allow end-users the ability to add new programming languages to the environment.)

Adding new syntax errors to the compiler takes only slightly more time than modifying an existing error message, but in general we have broken every check or test out into its own, separate unit of functionality—a separate compiler pass. This makes maintaining and extending the compiler a manageable, and even enjoyable, task. Finding code that fails unit tests also becomes a snap.

Another error a programmer might make is to define a process more than once; again, this is like having two methods in Java with the same name and same arguments—and this isn’t allowed. Likewise, in our little language, you can only define a named process once.

42-duplicate-definition-names
Duplicate definitions

Here, the first instance is highlighted (I can’t easily highlight all of them, unfortunately—but we’ll work on that), and the error message reports all the lines in the code where the process is defined. In this example, we have three definitions of foo in the source code. The compiler catches all three, tells me where they are, and highlights the first offending instance.

My personal goal is for every error message in the compiler to be this rich and informative. I’m considering instrumenting the compiler to catch errors it has never seen before, and report those errors directly back to us (with the user’s permission, of course). This way, as new syntax errors with poor messages are found, we can improve the compiler using real user data. This would provide valuable research data and a paper or two along the way.

As we now have our source code viewable, we’ll soon be making it publicly available. Please drop a note if you’re interested in working with or contributing to any of the tools we’re developing.


Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2020

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2020

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2392

Warning: implode() [function.implode]: Argument must be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3345

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3368

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3368

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3409

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3461

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3461

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3606

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3606

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2020

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2020

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2392

Warning: implode() [function.implode]: Argument must be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3345

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3368

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3368

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3409

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3461

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3461

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3606

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3606

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2020

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2020

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2392

Warning: implode() [function.implode]: Argument must be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3345

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3368

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3368

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3409

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3461

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3461

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3606

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3606

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2020

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2020

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2392

Warning: implode() [function.implode]: Argument must be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3345

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3368

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3368

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3409

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3461

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3461

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3606

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3606

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2020

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2020

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2392

Warning: implode() [function.implode]: Argument must be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3345

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3368

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3368

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3409

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3461

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3461

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3606

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3606

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2020

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2020

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2392

Warning: implode() [function.implode]: Argument must be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3345

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3368

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3368

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3409

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3461

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3461

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3606

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3606

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2020

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2020

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2392

Warning: implode() [function.implode]: Argument must be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3345

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3368

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3368

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3409

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3461

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3461

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3606

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3606

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2020

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2020

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2392

Warning: implode() [function.implode]: Argument must be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3345

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3368

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3368

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3409

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3461

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3461

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3606

Warning: Invalid argument supplied for foreach() in /home/jadudm/sububi.org/wp-content/plugins/wp-syntax/geshi/geshi.php on line 3606
All the world’s a stage, and this quote, often abused.

M. Jadud

What can an Actor do? Not as pressing a question as What Would an Actor Do? (WWAD?), but certainly an important question never-the-less. I want to remind the gentle reader that I have many grand schemes about great, sweeping themes and stories about agent-based programming in Java using Greenfoot… but at the moment, I’m just wandering around. And in my wanderings, I’d like to make the mushrooms in my LumpWorld wander around, too.

Of course, I don’t know how to do that. I could try and use Google to find out how, or I could go back and read the tutorial. However, I want to try something a little different. I’ll read some documentation.

Now, I know some of you are saying “Matt! Reading documentation! That’s awfully extreme, isn’t it?” Well, my friends, it is. Very extreme. And, for the record, it is very, very exciting. And Greenfoot has plenty of documentation hidden inside it, if you know where to look.


greenfoot-actor-classes

Documentation be hidden in them thar classes…

Lets start with the Actor class. If I double-click on the Actor class, I get a whole mess of Java.


greenfoot-mess-o-java

Double-clicking the Actor class yields a mess-o-Java.

This mess-o-Java is not for the faint-of-heart. If you look at the top of the file, you’ll see that it is written by @author Poul Henriksen, which means that a crazy person wrote that code. And we all know what happens when crazy people write software. So be careful if you spend any serious time looking at this code. What is more interesting is in the upper-right-hand corner of this window: a little drop-down menu. It has two options: Implementation and Interface Go ahead and select Interface.


greenfoot-interface-documentation


Documentation regarding the Actor class.

This is more like it! The interface documentation tells us about all the things we can do with an Actor object. For example, in my last example, I used the setRotation method; we can see that it is documented here, and not just in the Wombats tutorial. Along with it is a method called setLocation. The method summary is really quite straight-forward:

void setLocation(int x, int y)
          Assign a new location for this object.

This method consumes two integers, and returns nothing. I’m guessing it is a magic teleport method, and probably should have been called magicTeleporter(int x, int y), because it will magically make your Actor jump to anyplace in the Greenfoot World. I’m going to take my existing act() method:

public void act()
    {
        lump_rotation = lump_rotation + 1;
        setRotation(lump_rotation);
    }

and I’m going to modify it just a bit. I’m going to make my mushrooms wander around while they’re rotating.

A first attempt

The neat thing about sitting down to a piece of software as rich as Greenfoot is that you can find things you don’t expect. Put another way, I can come to the table with all kinds of assumptions, pre-conceived notions, and expectations about how Greenfoot should or will work, and then be surprised when it doesn’t work that way. Since the point of this blog is to wander around Greenfoot “kicking the tires” (so to speak), I might as well talk about some of my failures along side some of my successes, no?

Here was my first attempt at making a Lump that would march across the screen:

public class Lump extends Actor
{
    private int lump_rotation;
    private int lump_X;
    public Lump()
    {
       lump_X = getX();
    }
 
    public void act()
    {
        lump_rotation = lump_rotation + 1;
        setRotation(lump_rotation);
        // Move the Lump around!
        lump_X = lump_X + 1;
        setLocation(lump_X, getY());
    }
 
}

My previous post explored making my Lumps rotate around their axes; this would have them spinning and marching around. However, this code has a significant problem that didn’t really make sense to me at first:

java.lang.IllegalStateException: The actor has not been inserted into a world
                                 so it has no location yet. You might want to look at the
                                 method addedToWorld on the Actor class.
	at greenfoot.Actor.failIfNotInWorld(Actor.java:537)
	at greenfoot.Actor.getX(Actor.java:103)
	at Lump.<init>(Lump.java:23)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
	at greenfoot.core.WorldInvokeListener$2.run(WorldInvokeListener.java:150)

You see, I put the call getX() in the constructor for my Actor. (The constructor is a special Java class method that is called when a new object is created. It always has the same name as the class—in this case, it is called Lump().) When I right-click to create a new Lump() object, everything is fine… until I try and put it in the world. At this point, the object is created, but it doesn’t yet exist in the world. So, everything goes badly for my Lump, and this exception is thrown.

That’s cool. Since this post is about reading documentation, I then went back to the documentation I mentioned earlier and started reading. Sure enough, the docs tell me that I can’t do what I tried to do. Because I’m a slow monkey, it looks like the documentation might become even more explicit about this point—that would be cool. While reading more carefully, I discovered the addedToWorld() method. This fits in thusly:

  1. You right-click to create a new Actor object
  2. You drop your Actor on the World
  3. Your Actor’s constructor is called
  4. Your Actor’s addedToWorld() is called

Now, I’m sure other nifty things happen in there, but this is enough for us to be getting on with.

A second attempt

Now that I’ve learned to stop fearing Greenfoot, and learned to love the documentation, my life has been much, much better. My next attempt at making my Actor wander around was much better.

public class Lump extends Actor
{
    private int lump_rotation;
    private int lump_X;
    public Lump()
    {
 
    }
 
    public void addedToWorld(greenfoot.World world) {
       lump_X = getX();
    }
 
    public void act()
    {
        lump_rotation = lump_rotation + 1;
        setRotation(lump_rotation);
        // Move the Lump around!
        lump_X = lump_X + 1;
        setLocation(lump_X, getY());
    }
 
}

Now, my Lump correctly drops into the World! Woot! What happened next, however, was not expected; I’ve created a video to demonstrate what I encountered next.


greenfoot-exception-image

A video of my first Greenfoot exception! (6.9MB, right-click to download.)

An exception! In particular, this text popped up on my screen: