documentation/Basics

Here are some pointers on how to use more complex code

Multiline Statements

If a statement is followed by three dots, multiline input mode is activated (not for the '/pymacro' command)

/py def foo():...

During multiline mode, any additional line requires no further leading command /py

.print "bar"

As leading spaces in chat messages are stripped by bukkit, indendation is done by starting the line with a single dot per indendation level
The statement is terminated by either a single empty line (or any number of dots that are converted to spaces, in case of execution from ingame chat empty chat messages are not sent),

.

or the command "macro name", to save the multiline statement as a macro

macro def_foo

in this case the resulting macro is named 'def_foo'

To summarize, this input

/py def foo():...
.print "bar"
.

Results in the following python code being executed:

def foo():
    print "bar"

You can then use the newly defined function with for example

/py foo()

Interactive Mode

In interactive mode, the console/chat basically works like the python interactive interpreter, with the exception of multiline statements (for loops or function definitions) which work as described above

So the only difference to executing code via /py is that you don't need the command, and you cannot define single statement macros since chat commands are circumvented

To exit the interpreter, type 'exit' (or 'stop' from the server console if you want to also shutdown the server)


Comments

Posts Quoted:
Reply
Clear All Quotes