Entry point execution

Whenever a plugin is started, it will first call the Main() function. This function is also known as a coroutine, meaning it can be suspended (yielded) to give the execution back to the game (and other Openplanet plugins). If you're familiar with ManiaScript, then the execution flow should look familiar.

Let's demonstrate this. Make sure you have the Openplanet log open in the overlay (Openplanet -> Log). Put this code in your Main() function:

void Main()
  while (true) {
    print("Hello, world!");

If you save the file and reload the scripts in Openplanet, you will see the log print "Hello, world!" every second:

In the script, we've added an infinite loop while (true) and within that, we are printing "Hello, world!", and then suspending script execution for 1000 milliseconds (1 second) with sleep(1000).

If you change the sleep delay to 0 milliseconds, execution will be returned the next game frame. A shortcut for this is to simply call yield().

Note: If you're familiar with this concept from ManiaScript, be advised that in ManiaScript gamemodes, script execution is at a fixed rate of 100 FPS, while in Openplanet all plugins run at the render framerate.

Continue to the next page: Creating menu options

Page updated 2 years ago by Miss