Skip to content

Runtime Modes

Southclaws edited this page Mar 9, 2018 · 5 revisions

1.6 introduced a powerful new feature for package development called Runtime Modes. These are designed for package development and provide ways to run Pawn code more like a traditional programming language.

There are three runtime modes:

  • server
  • main
  • y_testing

To use, add a mode field to the runtime field in your Package Definition File:

{
  "entry": "test.pwn",
  "output": "test.amx",
  "dependencies": ["sampctl/samp-stdlib"],
  "runtime": {
    "mode": "main"
  }
}

server

Server is the default mode, this does nothing special, it simply runs the server and waits for the server to exit by itself. This is what you want if your package provides in-game features (such as an editor tool or a demonstration of your library).

Please note that during this mode, if the server crashes it will be automatically restarted.

main

In the above example, the mode main has been used which means when you run sampctl package run, the process will exit as soon as the main() function has finished. If you run this from a console, it means you return to the prompt straight after instead of needing to press CTRL+C to close the server.

This is most useful for quick tests and code-only proof-of-concepts.

This behaviour will be familiar to anyone who uses languages such as C or Go - in those languages, the program exits as soon as it has reached the end of main().

y_testing

This mode is specifically designed for code that uses y_testing for unit testing code. If the tests pass, the exit code of sampctl is 0 and if the tests fail, the exit code is 1 making this a perfect tool to use in continuous integration tools such as TravisCI.

For an example of a fully unit-tested package that uses this feature, check out samp-ini.

Clone this wiki locally