Wiz Programming Tutorials

OK, so you want to get started programming in Jython. How do you do it? There's a lot of documentation on this website, and we're writing tons more, but you have to read this first, or you'll be totally lost.

Contents

Step 1: Stuff You Need

You need:
  • To be a Senior Wizard. Non-seniors don't have permission to write python code. To get to be a Senior, you have to get a sponsor, and have them help you write some code. When you've got some working code, and you can demonstrate that you're going to be doing it a fair amount, we'll consider promoting you.

  • The Wyvern Map Editor.

  • A Text Editor — any one will do. It has to write files as plain-text, so you shouldn't use a Word Processor like Microsoft Word. (You can, but make sure you save the files as plain text, with no formatting).

That's all you need. You do not need Jython or Python or Java on your home computer. You can download them if you like, to practice writing code, but you won't be able to call any game functions.

Step 2: Start Coding

We use "Python" and "Jython" interchangeably. We use Jython, which is a version of Python written for Java. Confused yet?

You can create your own game objects in Jython, ones that do all sorts of neat things. The steps are:

  1. Create a jython file that ends in ".py".
  2. Upload the file to the server with the Upload File dialog in the map editor. We'll explain this more.
  3. Clone the object with the wizard clone command, which stick it in your inventory.
  4. (Possibly) drop it in the map you're standing in.
  5. Activate it, however it's been coded to be activated.

OK, that's the basic overview — let's go into some more details.

Create a Jython File

We've got lots of tutorials, so we won't go into the coding here. Just follow these instructions to try your first "Hello, World!" program.

First, copy the following code into your Text Editor, and save it in a file called hello.py, somewhere on your home computer. The best place to put it would be in wyvern/wiz/yourname/py/hello.py, wherever you have wyvern installed, because that's where you will put it on the server. It's nice to have the files in the same places on both computers.

<span class='keyword'></span>from<span class='keyword'></span> <span class='keyword'></span>java<span class='keyword'></span>.<span class='keyword'></span>lang<span class='keyword'></span> <span class='keyword'></span>import<span class='keyword'></span> <span class='keyword'></span>String<span class='keyword'></span><br><span class='keyword'></span>from<span class='keyword'></span> <span class='keyword'></span>wyvern<span class='keyword'></span>.<span class='keyword'></span>lib<span class='keyword'></span> <span class='keyword'></span>import<span class='keyword'></span> <span class='keyword'></span>Command<span class='keyword'></span><br><span class='keyword'></span>from<span class='keyword'></span> <span class='keyword'></span>wyvern<span class='keyword'></span>.<span class='keyword'></span>lib<span class='keyword'></span>.<span class='keyword'></span>classes<span class='keyword'></span> <span class='keyword'></span>import<span class='keyword'></span> <span class='keyword'></span>DynamicObject<span class='keyword'></span><br><br><span class='comment'># lets you type "hello" and it'll spit out "Hello, World"</span><br><span class='keyword'>class</span> <span class='function'>hello</span>(DynamicObject, Command):<br>    <span class='string'>"""</span><span class='keyword'></span>This<span class='keyword'></span> <span class='keyword'></span>class<span class='keyword'></span> <span class='keyword'></span>is<span class='keyword'></span> <span class='keyword'></span>a<span class='keyword'></span> <span class='keyword'></span>super<span class='keyword'></span>-<span class='keyword'></span>bitchin<span class='keyword'></span>',<br>       <span class='keyword'></span>totally<span class='keyword'></span> <span class='keyword'></span>awesome<span class='keyword'></span>,<br>       <span class='keyword'></span>inspiring<span class='keyword'></span> <span class='keyword'></span>piece<span class='keyword'></span> <span class='keyword'></span>of<span class='keyword'></span> <span class='keyword'></span>work<span class='keyword'></span>.<br>    <span class='string'>"""</span><br>    <span class='keyword'>def</span> <span class='function'>initialize</span>(self):<br>        <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>super__initialize<span class='keyword'></span>()<br>        <span class='keyword'></span><span class='instance'>self</span><span class='keyword'></span>.<span class='keyword'></span>setImage<span class='keyword'></span>(<span class='string'>"<span class='keyword'></span>objects<span class='keyword'></span>/<span class='keyword'></span>jade_key<span class='keyword'></span>"</span>)<br><br>    <span class='keyword'>def</span> <span class='function'>knowsCommand</span>(self, cmd):<br>        <span class='keyword'></span>return<span class='keyword'></span> <span class='keyword'></span>String<span class='keyword'></span>.<span class='keyword'></span>equals<span class='keyword'></span>(<span class='keyword'></span>cmd<span class='keyword'></span>, <span class='string'>"<span class='keyword'></span>hello<span class='keyword'></span>"</span>)<br><br>    <span class='keyword'>def</span> <span class='function'>createEvent</span>(self, event):<br>        <span class='keyword'></span>return<span class='keyword'></span> <span class='keyword'></span>event<span class='keyword'></span><br><br>    <span class='keyword'>def</span> <span class='function'>execute</span>(self, event):<br>        <span class='keyword'></span>agent<span class='keyword'></span> = <span class='keyword'></span>event<span class='keyword'></span>.<span class='keyword'></span>getAgent<span class='keyword'></span>()<br>        <span class='keyword'></span>agent<span class='keyword'></span>.<span class='keyword'></span>message<span class='keyword'></span>(<span class='string'>"<span class='keyword'></span>Hello<span class='keyword'></span>, <span class='keyword'></span>World<span class='keyword'></span>!"</span>)<br><br>    <span class='keyword'>def</span> <span class='function'>toString</span>(self):<br>        <span class='keyword'></span>return<span class='keyword'></span> <span class='string'>"<span class='keyword'></span>hello<span class='keyword'></span> <span class='keyword'></span>tester<span class='keyword'></span>"</span>

OK, now that you've created hello.py, it's time to upload it to the server.

Upload The File

Now go to the Upload Files dialog in the Map Editor, and fill out the fields like so:

Server: opal.cabochon.com
Username: you
Password: your password
File: c:\games\wyvern\wiz\you\py\hello.py
Save To: py/hello.py

Make sure the path in the File: field is wherever you saved the file on your home machine.

Then hit Upload and watch it go.

It will be placed in your wiz directory, in a subdirectory called py/, which is a nice place to keep all your python files.

Clone the Object

OK, now log into Wyvern, if you weren't already there, and type:

    clone wiz/myname/py/hello.py

It should say:

    A new hello tester has been placed in your inventory.

If it doesn't say that, then you've done something wrong — go back to the top and start over again.

Now you have a "hello tester" in your inventory. It should look like a jade key, since that's what we set the appearance to.

Now type:

    hello

And it should tell you:

    Hello, World!

That's all there is to it!

Using your jython class in an archetype

If you want to use your object in a map, you can create an archetype to wrap your class. Using the your text editor, create a file called wiz/yourname/arch/hello.arch, and put this inside it:

<arch path="wiz/yourname/arch/hello.arch"/>

Just that one line, exactly like it's typed above, except with your wiz name instead of "yourname". Upload it as follows:

Server: opal.cabochon.com
Username: you
Password: your password
File: c:\games\wyvern\wiz\you\arch\hello.arch
Save To: arch/hello.arch

Now you can clone the archetype directly:

    clone wiz/yourname/arch/hello

You can also see the archetype in the Map Editor, and put it into the map.

Now you're ready to go read about coding in Wyvern, which is nontrivial (but at least we have lots of tutorials).

Next Chapter >>