Changes between Initial Version and Version 1 of Scripting


Ignore:
Timestamp:
04/06/18 16:32:56 (12 months ago)
Author:
admin
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Scripting

    v1 v1  
     1= Scripting =
     2
     3!WorldPainter has a scripting engine which you can use to:
     4 1. Perform operations on the command line on computers without a graphical user interface, such as servers.
     5 1. Perform advanced operations that aren't currently possible with the GUI.
     6 1. Automate sequences of commonly executed operations
     7
     8The currently available operations in the scripting engine are:
     9 * Creating new worlds from height maps
     10 * Exporting worlds to Minecraft maps
     11 * Applying height maps or masks as layers or terrain types
     12 * Setting layers or the terrain according to filters
     13 * Etc...
     14
     15The scripts are written in !JavaScript, although it is possible to install support for other scripting languages.
     16
     17= Running Scripts =
     18
     19There are two ways to run scripts: inside !WorldPainter using `Tools` -> `Run script...` or from the command line using the `wpscript` command.
     20
     21== Inside !WorldPainter ==
     22
     23To run scripts from inside !WorldPainter, open the Run Script screen by selecting Run script... from the Tools menu. You can select a previously executed script from the drop down list, or you can load a new script by pressing the `...` button. You can pass parameters to the script by entering them in the "Parameters" text area (one parameter per line). These will be available to the script in the `arguments` (from index 0) and `argv` (from index 1) arrays. Press `Run` to run the script. If it writes to the console the output will be displayed in the "Output" text area.
     24
     25Scripts executed from inside !WorldPainter have access to the currently loaded world and currently selected dimension, so that they can manipulate them.
     26
     27== The Command Line ==
     28
     29!WorldPainter scripts can be run from your operating system's command line, using the `wpscript` command. The "command line" is a way to interact with the operating system of your computer by typing textual commands with your keyboard and receiving the results as text on the screen, using a terminal window. On Windows the quickest way to open a terminal window is to press the Windows key, type `cmd` and press Enter.
     30
     31Regardless of the operating system you run scripts with the `wpscript` command, which should automatically be available on the command line after installing !WorldPainter:
     32
     33{{{
     34wpscript <scriptfile> [<scriptarg> ...]
     35}}}
     36
     37Where `<scriptfile>` is the filename of the script, including extension, which can optionally be followed by one or more script arguments. The arguments will be available to the script in the `arguments` array (starting from index 0) or the `argv` array (starting from index 1).
     38
     39= Script files =
     40
     41Script files are text files with a name of your choice, but the extension should reflect the scripting language. These pages assume !JavaScript, which most Java runtimes should support, for which the extension of your script files should be: `.js`.
     42
     43You can create them with any text editor, such as Notepad on Windows, or a dedicated IDE or programmers' editor which might provide !JavaScript syntax highlighting and code completion.
     44
     45= API =
     46
     47The !WorldPainter functionality is made available to the script in the form of a context object named `wp`. For details about the available operations on the !WorldPainter scripting context, see the [wiki:Scripting/API API] page.
     48
     49= Examples =
     50
     51Here are a few example scripts to show what you can do, and how you would do it:
     52
     53[wiki:Scripting/Example1 Creating a world from a height map and applying layers]
     54
     55A complete example of creating a new world from a height map, and using other height maps to add forests and rivers.