Alice originally included a Python scripting language component that was a significant part of the core Alice development environment. The release of Alice 2.0 saw a complete rewrite of the application in Java and a reduction in its dependence on scripting. As of the latest release (2.0 04/05/2005), scripting support is disabled and there is no option to turn it on in the program's preferences configuration UI. However, Alice still supports a potentially rich scripting environment using the Jython Python implementation as its interpreter. Scripts in Alice have access to Alice's objects, a significant portion of the Python module library, and a large part of the Java API.

Enabling Scripting Support

To enable scripting support, you will need to edit Alice's configuration file, which is an XML document stored in the current user's Documents and Settings folder:

C:\Documents and Settings\daniel\.alice\AlicePreferences.xml

where "daniel" is your Windows user name. Be sure that Alice is closed and open up this file in your favorite text editor (don't bother with the fancy XML editor: it is overkill for what you need to do here). Browse or search for the following section (around line 198 on my system):

<key visibility="open">
    <name>enableScripting</name>
    <value>false</value>
</key>

and change the value false to true to enable scripting. Save the file and exit your editor. Note that Alice may occasionally overwrite the configuration file, so you may have to redo this change from time to time.

Start Alice and verify that scripting is enabled by looking for the interpreter bar over the scene preview:

images/scripting_enabled.png

Script Portability

A handy feature of Alice's scripting support is that it is always available to run scripts: the above instructions enable you to create and edit scripts, but Alice will run scripts even if editing is disabled. Practically speaking, this means that you can create worlds that use Alice scripting and distribute them to anyone. Recipients can run the program on an unmodified Alice installation without knowing anything about Alice's scripting backend. How cool is that? :-)

Caveat

While scripting support in Alice 2.0 appears fairly broad, it does not appear to be a particularly well supported feature. Most of this information was discovered through trial and error and rooting through the source code, so be prepared for some errors, oversights, and omissions. Some of the problems I have encountered:

  • While there are a large number of Python modules available, importing some of them (notably the network modules) does not appear to work correctly: the import stops before all of the module's symbols have been loaded.
  • Importing some Python modules may result in a cryptic syntax error related to an undefined future/division operator (?)
  • I have not managed to get function return values working yet.