python_getstarted
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| python_getstarted [2017/12/30 17:13] – [Getting Started] g00r00 | python_getstarted [2023/01/20 02:28] (current) – [Getting Started with Scripting] g00r00 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== Getting Started ===== | + | ===== Getting Started |
| + | |||
| + | //Note: This section assumes you've already performed the installation of | ||
| + | Mystic Python as covered in the [[python_install|Installation]] section.// | ||
| This section will cover the very basics for creating your first | This section will cover the very basics for creating your first | ||
| Line 7: | Line 10: | ||
| The goal of this section is not to teach you Python, but to show you | The goal of this section is not to teach you Python, but to show you | ||
| how to get started specifically with Mystic' | how to get started specifically with Mystic' | ||
| - | many Python | + | many Python references and tutorials all over the Internet to help develop |
| the skills needed to create your Python programs. | the skills needed to create your Python programs. | ||
| - | scripting language used both at the hobby and professional levels and the | + | scripting language used both at the hobby and professional levels, and the |
| resources available via Google are plentiful. | resources available via Google are plentiful. | ||
| - | |||
| - | This section assumes you've already performed the installation of | ||
| - | Mystic Python as covered in the [[python_install|Installation]] section. | ||
| + | ---- | ||
| ==== Creating a Script ==== | ==== Creating a Script ==== | ||
| Line 52: | Line 53: | ||
| writeln(" | writeln(" | ||
| - | Once this line has been added to the top, then the first of the script contains | + | Once this line has been added to the top, then the rest of the script contains |
| - | your Python code. | + | 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(" | ||
| + | writeln(" | ||
| + | |||
| + | |||
| + | Refer to the [[python_functions|function reference]] and [[python_examples|Python examples]] section for more information on Python functions available as part of the Mystic module. | ||
| + | |||
| + | ---- | ||
| ==== Executing a Python Script ==== | ==== 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 " | ||
| + | command for Python 2, or the " | ||
| + | Mystic looks in the theme' | ||
| + | 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' | ||
| + | * If you supply a full path and filename, Mystic will execute it. | ||
| + | |||
| + | For example: | ||
| + | |||
| + | Menu Command: GY (Execute Python 2 Script) | ||
| + | Data: testpython | ||
| + | |||
| + | The above example will execute " | ||
| + | directory if it exists. | ||
| + | same from the default script directory if "theme fallback" | ||
| + | |||
| + | To execute Python 3, you'd use the GZ menu command instead of GY. | ||
| + | |||
| + | === By Prompt Replacement === | ||
| + | |||
| + | Any prompt can be replaced by a Python script by beginning the prompt with | ||
| + | a # character followed by the filename. | ||
| + | theme' | ||
| + | |||
| + | 001 #mypython | ||
| + | |||
| + | The above example would execute mypython.mpy with Python 2.7 from the theme' | ||
| + | directory in place of system prompt #001. | ||
| + | |||
| + | To execute a Python 3 script from a prompt, use the ~ character instead of # | ||
| + | |||
| + | === By Command Line === | ||
| + | |||
| + | Mystic Python scripts can be executed directly from the command line by | ||
| + | using the -Y and -Z options, 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 Python 2 script testpython from the user's theme script | ||
| + | directory applying the same logic as defined above for the path/ | ||
| + | conversions in Mystic Python. | ||
| + | instead of -Y. | ||
| + | |||
| + | === Through MPL Hooks === | ||
| + | |||
| + | Mystic has hooks in various locations where functionality of Mystic can be completely replaced by MPL scripts, such as the user login and new user application processes. | ||
| + | |||
| + | This type of approach would allow the entire login and new user application process to be completely scripted in Python, for example. | ||
| + | |||
| + | A BBS can range from a completely scripted experience, to a completely customized theme without using any scripting, or anything in between. | ||
python_getstarted.1514675624.txt.gz · Last modified: by g00r00
