Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
ezeio2:scriptref:start [2019-09-02 18:04] – andreh | ezeio2:scriptref:start [2020-11-12 22:53] – johpar | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== Script reference ===== | ===== Script reference ===== | ||
- | {{indexmenu_n> | + | {{indexmenu_n> |
+ | |||
+ | === ezeio script programming - the PAWN language === | ||
+ | |||
+ | The scripting feature in the ezeio allows the user to implement advanced custom logic and control functionality on the ezeio. For most common applications, | ||
+ | |||
+ | The ezeio uses a powerful script language called PAWN. The syntax is very similar to JavaScript, and should be easily understood by anyone working with programming in similar languages. | ||
+ | |||
+ | The scripting feature of the ezeio is intended for those with previous experience in programming. This manual does not attempt to teach you to write programs. If you have a specific feature that you need help with, please contact eze System. | ||
+ | |||
+ | We strongly recommend reading the following documents to get introduced to the PAWN language: | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | |||
+ | === ezeio script administration === | ||
+ | |||
+ | When working with ezeio scripts, you will edit your code on the userscript screen. When clicking " | ||
+ | |||
+ | Only one user defined script can run at the same time, but the editor allows you to have multiple scripts saved on the servers, and easily switch between them. The currently running script is marked with a checkmark. | ||
+ | |||
+ | If a script fails to compile due to a syntax error, the script will not be sent to the ezeio. If a previous version of the script, or a different script, was running, this will continue to run. | ||
+ | |||
+ | === Script resources === | ||
+ | |||
+ | The user script can occupy up to 128kB code (compiled bytecode), and up to 16kB RAM. | ||
+ | |||
+ | The estimated requirements for a script is displayed when compiling. | ||
+ | |||
+ | === Programming pattern === | ||
+ | |||
+ | Although the user script runs in a sandboxed runtime engine, the recommended programming pattern is similar to [[https:// | ||
+ | |||
+ | This means that you should avoid long-running loops, and instead make use of system callbacks provided in the function library. | ||
+ | |||
+ | The following system callback functions are defined: | ||
+ | |||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | |||
+ | === State machines === | ||
+ | |||
+ | A common programming pattern in control applications is to use state machines. PAWN and the ezeio implements strong support for state machines. The following is a typical pattern showing the startup sequence of an engine. Note that there are three @Tick handlers; one for each state. Also note the " | ||
+ | |||
+ | <code javascript> | ||
+ | |||
+ | new count = 0; | ||
+ | |||
+ | main() | ||
+ | { | ||
+ | SetTickInterval(100); | ||
+ | state WAITING; | ||
+ | } | ||
+ | |||
+ | @Tick(uptime) < | ||
+ | { | ||
+ | if( GetField(1) < 100 ) // condition to start up the process | ||
+ | state IGNITION; | ||
+ | } | ||
+ | |||
+ | // ***** the IGNITION state | ||
+ | |||
+ | entry() < | ||
+ | { | ||
+ | | ||
+ | count = 0; | ||
+ | } | ||
+ | |||
+ | @Tick(uptime) < | ||
+ | { | ||
+ | if( GetField(2) > 100 ) // Did the engine start? | ||
+ | state RUNNING; | ||
+ | |||
+ | | ||
+ | state WAITING; | ||
+ | } | ||
+ | |||
+ | exit() < | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | |||
+ | // ***** the RUNNING state | ||
+ | |||
+ | @Tick(uptime) < | ||
+ | { | ||
+ | if( GetField(2) < 100 ) // Check if the engine stopped | ||
+ | state WAITING; | ||
+ | } | ||
+ | |||
+ | </ | ||