Once again I'd like to get more people interested in making scripts for the game. Scripting is not easy to learn but it's worth it. Classic modding only gives you so many options, and for any addition or improvement, you have to wait until devs have time and energy. Not so with scripting - the game already offers pretty much anything you will need, and even if not, extending the scripting is much less work for the developers than with any other modding fileformat.
This thread will give you bite-sized steps to follow, from the simplest and most intuitive to the more involved. You don't need to know anything about programming and you will not be taught here either - instead you'll find out what tools and tricks the game offers to have fun learning later.
This is an outline. I'll expand on every step in later posts with examples and screenshots:
This thread will give you bite-sized steps to follow, from the simplest and most intuitive to the more involved. You don't need to know anything about programming and you will not be taught here either - instead you'll find out what tools and tricks the game offers to have fun learning later.
This is an outline. I'll expand on every step in later posts with examples and screenshots:
- How to use the game console.
Open it from top menu / tools / show console or by hotkey '`' (the '~' key on top left of keyboard, under Esc). There, in the "Command" box below, type "as" followed by whatever and hit "Submit" button or Enter. The game will try running whatever as a script - so you'll likely get an error. For example, typing just "as" is fine, "as blabla" produces an error "No matching symbol 'blabla'"
To erase the text in console, use "clear" command. To see all commands, use the 'Commands' menu on top of the console window, or type "help" command. Pressing the 'Up' hotkey while typing will bring back the previous submitted command. Tip: you can actually use the console from main menu, but know that the menu listens to arrow keys and Enter key, so open "credits" window first, otherwise you'll exit your game by accident - happened to me several times 
- Your first working console script.
Type "as game.openUrlInDefaultBrowser('http://www.rigsofrods.org');" and submit - game will minimize and your web browser will jump up with Rigs of Rods website open. If nothing happened, make sure the "http://" or "https://" bit isn't missing, it doesn't work otherwise. Congrats, you've just made the game do something you can't do via any modding or UI. Strictly speaking, there are some hyperlinks here and there, like repo links in RepositoryUI, but those don't let you open any website you want. - More useful console scripts.
Type "as game.log('Hello Rigs of Rods');" and submit - you'll see the message repeated in the console. If you close the console window quickly enough, you'll see the message in the chatbox area (bottom left of screen) until it disappears. This is how messages are displayed in the chatbox (or console if it's open). You'll be using this a lot while scripting.
A more complicated example: copypaste this into the console: "as game.showMessageBox("hello box","hello Rigs of Rods", false, "a", true, false, "b");" and submit - this will open a message box. To find out what all the parameters mean, see game.showMessageBox() in docs.
One more fun example: "as game.spawnObject("sign-deer", "myDeer01", game.getPersonPosition(), vector3(0,0,0), "!supress", false);" will add a road sign where your character is currently standing! To remove it again, do "as game.destroyObject("myDeer01");" - Enter the Script editor.
Now that you know some script snippets that actually do stuff in the game, you'll need some bigger textbox to input and edit them, ideally with the option to save and load. In the game top menu, select Tools/Browse gadgets... and in the Loader UI, select "script editor". This will open a window which works like a text editor: there are line numbers on the left in bright yellow color (the other numbers are just funny decorations, you can disable them using the View menu) and on the right, there is the editable text with pre-created example script. There's a "[>>] RUN" button on the top bar - press it and it wil run the script and change to "[X] STOP". Don't worry about the example script being so complicated - unlike the console, the editor can only run a complete programs, not just one-off snippets, but there isn't much to understand. Just know that hitting RUN with completely empty script is OK - the script will load, it will just be completely useless, never actually doing any work. To reset the Tutorial script to original, just close it - it will immediatelly reopen with exactly the startup content. - Seeing and stopping scripts.
Go back to the console window and open the "Script monitor" menu - you will see a table with heading 'ID | Filename | Options' and 2 horizontal sections: 'Active' and 'Recent'. If you're in menu, both will be empty. If on terrain, you'll see one script, usually with filename "default.as" and options "(terrain)". If script editor gadget is running, you'll see it as additional script with filename "script_editor.gadget" and options "Reload/Stop/Autoload". Yes, gadgets are actually scripts themselves and futher down this tutorial, you'll learn to make your own! The buttons stop or restart the script - try it! The Autoload checkbox will make the script start automatically next time you run the game. Finally, if you also run the example script in script_editor, you'll see it too.
One thing to take note of is the ID column in the script monitor - this shows the "Script Unit ID" (or NID for short - yes it's a little strange but both SID and SUID were already taken, so I used the next letter: uNit ;-). If the example in script editor is running, you will see the bottom bar say "RUNNING (NID: 123)" where 123 is the same value as the ID in the script monitor. When you know the NID, you can ask the game about the script details, change it's settings or stop it.
For a technical reference to the scripting language, visit