๐ŸŽข Episode 2 ยท Beginner ยท First Code

Hello, Park
Episode 2: Your First Plugin

Time for your first line of real code. You will write a tiny plugin, watch the game load it, and read its message in the console. This is the moment you become a modder.

๐Ÿ‘ถ Ages 10+ โฑ๏ธ ~40 mins ๐ŸŽข OpenRCT2 โœ“ Free workshop
๐Ÿ“œ registerPlugin ๐Ÿ–ฅ๏ธ console.log ๐Ÿ”” Events โœ… Load check
โญ
0 XP
Level 1
๐Ÿ”ฅ0
Your Progress 0 / 5 steps
Build it in our OpenRCT2 Studio too: set up a park plugin, wire up events, read the park and export real plugin files in the browser, with no install. Open the OpenRCT2 Mod Studio →
๐Ÿ”ฅ
Ember says: a plugin is one function plus a registration call. That is it. Do not worry about the big words, we will meet them one at a time.
1
๐Ÿ“ฆ
What a Plugin Is
One function, one registration
Active
๐ŸŽฏ
Goal for this step

Understand the two parts every plugin has.

  • 1A .js file holds your code.
  • 2A function (called main) is the work you want done.
  • 3registerPlugin tells OpenRCT2 the plugin exists and points it at your function.
โœ๏ธ
Fill in the Blanks
+15 XP
The function the game runs is usually called , and it is announced with .
๐Ÿง 
Knowledge Check
+15 XP
What are the two parts of every plugin?
AA function and a registerPlugin call
BA sprite and a sound
CA username and a password
2
โœ๏ธ
Write hello.js
Four lines that prove it works
Locked
๐ŸŽฏ
Goal for this step

Save a working plugin in your plugin folder.

  • 1Open your text editor and create a new file.
  • 2Type the code below exactly.
  • 3Save it inside your plugin folder as hello.js. Make sure it is not hello.js.txt.
function main() {
  console.log("Hello park! My first plugin is running.");
}

registerPlugin({
  name: "Hello Park",
  version: "1.0",
  authors: ["Your Name"],
  type: "local",
  main: main
});
๐Ÿง 
Knowledge Check
+15 XP
Which property points to the function to run?
Astart
Bmain
Crun
3
๐Ÿ””
React to the Park
Run code when something happens
Locked
๐ŸŽฏ
Goal for this step

Make your plugin do something when a new day starts.

  • 1OpenRCT2 gives you events you can listen to, like interval.day.
  • 2context.subscribe attaches your code to an event.
  • 3park.postMessage shows a message in the game, like a park announcement.
function main() {
  context.subscribe("interval.day", function () {
    park.postMessage("A new day dawns in your park!");
  });
}

registerPlugin({
  name: "Daily Greeting",
  version: "1.0",
  authors: ["Your Name"],
  type: "local",
  main: main
});
โœ๏ธ
Fill in the Blanks
+15 XP
You attach to an event with context. and show a message with park..
๐Ÿง 
Knowledge Check
+15 XP
What does context.subscribe do?
ABuys a season pass
BRuns your code when a chosen event happens
CDeletes your park
4
โœ…
Check It Loaded
Read the plugin manager
Locked
๐ŸŽฏ
Goal for this step

Prove the game loaded your file and ran your code.

  • 1Open the Plugin Manager from the developer tools. Your plugin should be listed.
  • 2Open the game console and find your printed message.
  • 3If it is missing: check the file is in the plugin folder and ends in .js (not .txt).
  • 4Fix any missing bracket or quote and save again.
โœ๏ธ
Fill in the Blanks
+15 XP
A plugin with a missing bracket will not .
๐Ÿง 
Knowledge Check
+15 XP
Your plugin is not listed. Most likely cause?
AThe PC is too slow
BThe file is in the wrong folder or ends up as .js.txt
CPlugins only work at night
5
๐ŸŽจ
Make It Yours
Change the words, make it personal
Locked
๐ŸŽฏ
Goal for this step

Edit the message and the plugin name.

  • 1Change the name to something with your own style.
  • 2Change the message to greet your park by its name.
  • 3Save, reload, and watch it appear.
โœ๏ธ
Fill in the Blanks
+15 XP
Small changes are the best way to how the code works.
๐Ÿง 
Knowledge Check
+15 XP
What is the best way to learn what a line does?
AChange it and see what happens
BNever touch it
CDelete the file
๐ŸŽ‰โœจ๐Ÿ†๐ŸŽ‰
You Are a Modder!
You wrote a plugin, the engine loaded it, and it reacted to the park. Next you will make it post messages on your command.
0
Total XP
1
Level
0
Best Streak
0%
Accuracy
Next: Episode 3: Events and Messages โ†’