Status of Exporting Code from Enchanting

In the far-too-brief periods of time I’ve been able to put into Enchanting of late, I’ve been working on making it so that you can export code. I wanted to put up some incomplete results of my work.

If I construct the following script:

Sample Line-Follower Program

middle click on the sprite that owns the script and choose “export code”:

Export Code (context sensitive menu)

a window pops up with the text converted into a Java-esque format:

    public void WhenGreenFlagClicked()
    {
        // GoTo(-100, 0);
        // ClearDisplay();
        // PenDown();
        // PlaySound();
        // PlayDrum(48, 0.2);
        // WaitSecs(RandomRange(1, 10) / 5);
        // WaitSecs(Math.pow(Math.E, 10));
    }

public void WhenGreenFlagClicked() { LightSensor.SetMaxPoint(LightSensor.GetRawReading()); LightSensor.SetMinPoint(LightSensor.GetRawReading()); LeftMotor.runUnlimited(); Right Motor.runUnlimited(); for (int i = 0; i < n; ++i) { if (LightSensor.GetRawReading() > LightSensor.GetMaxPoint()) { LightSensor.SetMaxPoint(LightSensor.GetRawReading()); } if (LightSensor.GetRawReading() < LightSensor.GetMinPoint()) { LightSensor.SetMinPoint(LightSensor.GetRawReading()); } } while(true) { LeftMotor.setPower(LightSensor.GetBrightness()); Right Motor.setPower(); } }

There are still flaws and shortcomings to overcome, and it isn’t real code yet, but I’m pleased with the progress.

If you want to try it out (without getting the latest from version control), download this snapshot of the program, drag and drop Enchanting.image onto your Enchanting.exe or Enchanting.app, and have fun.

The files of note are:

  • the Enchanting.image file, which has all the code changes
  • locale/lejos.exp — a translation file used to translate from Scratch to the java-esque output (go ahead and play with it; it is reloaded every time you click export)
  • the ReferenceImages folder, which has pictures of the different code blocks with their block specification name in English. (This is handy for translating, and, if you hold down Shift and click on the file menu, there is an option to generate these files.)

Posted by Clinton Blackmore - Saturday August 14, 2010.
Posted in .

Comment