Posted on

Write a Reascript: Hello, World

Happy 2017 everybody!  Hope it’s seeing you well.  It’s a super sunny (albeit cold) day here in Seattle, so I’m going to enjoy that and get on teaching you some Reascript!

Hello, World

Once again – I’m aiming this at audio folks who have never programmed a line of code in their lives.  Don’t worry friends, we’ll get complicated in due time but today we’re going to give you a “quick win” and have you write the most simple Reascript that you possibly can.

If you’ve never programmed before, let me introduce you to the “Hello, World!” concept.  In (most) programming tutorials that start you from the ground up, the very first thing you write will be a program that prints the text “Hello, World!” on the screen.

This seems like a dumb thing, let me assure you though once I agreed with you – it’s not.

“Hello, World!” in our case accomplishes a few seriously important things:

  1. We’re making sure all of your components work.  ie: Did you install Reaper right?  Is that working?  Will Reascripts operate correctly?  If we don’t get past this – we have big big problems
  2. It teaches you how to print to the console.  The console in Reaper is a semi-secret place where only developers live.  When things go wrong, you’ll be using the console a lot to help you “debug” (aka hunt down problems in) code.
  3. It’s your first interaction working with the Reascript API.  So if you were incredibly confused with my last post – we’ll get to working with that code today.

Before we write the script

Ok, before we get our quick win, make sure you have the following things:

  1. A functioning Reaper installation, preferably the latest version.
  2. A text editor (Windows comes with Notepad – use it, not Word)

Once you’ve got those things, we’re off to the races.

SIDE NOTE:

While you can use something other than your Operating System’s default text editor, at this point if you’re brand new I don’t recommend it.  The program we’re writing is at worst 2 lines of code.  Do not waste your time trying to find the perfect code-writing software, just write code.

Your first Reascript

Ok, here we go – step by step with pictures!  I’m working in Windows, but this all should apply to Mac users as well.

  1. Open up that fancy-Dan text editor of yours!
  2. Type in reaper.ShowConsoleMsg(“Hello, World!”) as shown below
  3. Save this file JUST LIKE BELOW in any folder you can find later.  NOTE that you must change the file type to All Files because Notepad is inherently dumb.  Also, add “.lua” to the end of your file name.
  4. Open up Reaper and type Shift+? (this is the shortcut key for the Actions List)
  5. You should see the window below, click the “Load” button next to “Reascript” at the bottom.
  6. Your new Reascript should show up at the top.  Select it, and click the button that says “Run” at the very bottom.  You should see the window below if you did everything right.

Congratulations!

Sweet!  You’ve written and executed your first line of Reascript code and you’ve used the Reascript API!  Give yourself a pat on the back.

What you’ve done seems dumb and inconsequential, but it’s the first essential step to writing your own scripts.  I’m sure you wouldn’t call yourself this, but you are now a programmer – you are a person who can write programs (one, yes… but c’mon!)

A small step further

Do something for me real quick – “Run” your new script a few times in a row.  See something funky?  If you got this:

Hello, World!Hello, World!Hello, World!Hello, World!

You’re seeing what I’m talking about.

But what if you want only one Hello, World! at a time?

Or what if you want to stack a few lines on top of each other?

Below are two screenshots that solve both of those problems.

If you copy the above code, you’ll only ever see one Hello, World!.  Why?  That first line tells the console to print blank.  When you print a blank line, Reaper automatically removes all previous text from the console and clears it out.  You’ll use this a lot later on so your console doesn’t get cluttered.

If you copy the above code here, you’ll see a new command with “\n” on it.  The backslash n text is a sneaky way of telling Reaper to start a new line.  It’s like pressing Enter on Word.  With this code you should see two Hello, World! lines stacked on top of each other.

That’s it!

Alright – though it seems like a little, we’ve covered a ton of ground.  You now know enough to write multiple console programs.  Go crazy for a few minutes (before you get bored) and put some of your own text in the console.

Congratulations – you’ve made it through!  Next time we’re going to tackle another housekeeping item, code comments.  After that, we’ll get into futzing around with more legitimately neat stuff in Reaper.


Copyright 2016-2021, NIR LLC, all rights reserved.