User Tools

Site Tools





Visual Customization

Mystic Utilities (MUTIL)

Scripting Custom Modules

Quick Reference

What's New


Getting Started

Note: This section assumes you've already performed the installation of Mystic Python as covered in the Installation section.

This section will cover the very basics for creating your first Mystic Python script. A full function reference for all of the Mystic BBS module will be covered in a different section.

The goal of this section is not to teach you Python, but to show you how to get started specifically with Mystic's embedded Python. There are many Python 2 references and tutorials all over the Internet to help develop the skills needed to create your Python programs. Python is a very popular scripting language used both at the hobby and professional levels and the resources available via Google are plentiful.

Creating a Script

A Mystic Python script is simply a text file with Python code in it which can be executed by a number of ways within Mystic BBS. These can be edited with a source code editor or any text editor.

A script typically ends with the file extension of .mpy which stands for “Mystic Python.” This is the current recommended naming convention but in reality a script can have any name or extension that the developer desires to use.

Import Mystic Module

For each script, you first must import the Mystic BBS module at the top of your script by adding this line:

import mystic_bbs as bbs

This will give you all of the BBS related functions addressable with a bbs prefix. For example, you would write a line of text to the user with full MCI code support by using the prefix and function name:

bbs.writeln("This is a test!")

Alternatively you could import the Mystic BBS module without a prefix so that you can access the function names directly. Keep in mind that if you do this it is possible that a function name in the Mystic BBS library could conflict with another function name in a different module:

from mystic_bbs import *

This will give you access to all of the Mystic BBS functions without the need of a prefix, for example:

writeln("This is a test!")

Once this line has been added to the top, then the rest of the script contains your Python code. A very simple first script that simply prints “Hello World” to the user and then shows the pause prompt would look like this:

from mystic_bbs import *

writeln("Hello world!")

Executing a Python Script

There are numerous ways in which a Python script can be executed within Mystic BBS and this section assumes an understanding of how to create new menu commands, and how to edit prompts.

By Menu Command

Python scripts can be executed from your menus by using the “GY” menu command. By default Mystic looks in the theme's script directory for .mpy files using the same logic that Mystic Programming Language uses.

  • If you supply a file with no extension, Mystic will add .mpy to it
  • If you do not supply a path, Mystic will look in the theme's script directory and finally the default script directory if theme fallback is enabled.
  • If you supply a full path and filename, Mystic will execute it.

For example:

Menu Command: GY (Execute Python Script)
        Data: testpython

The above example will execute “testpython.mpy” from the theme's script directory if it exists. If it is not found, then it will try to do the same from the default script directory if “theme fallback” is enabled.

By Prompt Replacement

Any prompt can be replaced by a Python script by beginning the prompt with a # character followed by the filename. The script will execute from the theme's script directory. For example:

 001 #mypython

The above example would execute mypython.mpy from the theme's script directory in place of system prompt #001.

By Command Line

Mystic Python scripts can be executed directly from the command line by using the -Y option, but keep in mind a username and password must be supplied along with it. For example:

mystic -uSysop -ppassword -ytestpython

The above example will execute testpython from the user's theme script directory applying the same logic as defined above for the path/filename conversions in Mystic Python.

python_getstarted.txt · Last modified: 2018/01/01 15:36 by g00r00