Beginner’s Guide to Reaper Script
THREE THINGS
I couldn’t find a Reaper script that did exactly what I wanted. And my attempts to hack someone else’s code came up short. The Lua code used in Reaper didn’t look so weird to me that I couldn’t understand most of it. And it wasn’t difficult to find some pretty good resources for learning and understanding Lua. But like C, Lua takes a few different forms. So the first thing I needed: to learn how to write Lua specifically as implemented in Reaper.
Then there was a second part: the Reaper specific statements that are not in general Lua. I found the ReaScript API. But! It was more of a terse reference list than something organized for folks to learn from scratch.
Combining some Lua basics with the ReaScript API, I started coding. And I quickly realized I didn’t always understand what was happening when the script ran. The third thing I needed was: tracing. Specifically, to display values at key points in the progression through the code.
DISPLAY VALUES WITH: reaper.MB
I decided to use a Reaper specific statement for displaying values. The format is:
< reaper.MB (message, title, button option). >
For example, if we code this:

The resulting message box would be:

The zero value at the end specifies that single button at the bottom of the message box labelled “OK.” There are other button codes available, as detailed in the ReaScript API for the reaper.MB statement.
Forgive me getting super basic here, but for those who are not familiar with coding, one can store information in variables. Think of a variable as a box, a bag, or a container to hold information. And in Lua, you can use the statement local to define a variable just for this script. Local makes the variable disappear from memory when your code is finished executing, freeing up memory for other tasks. So here’s how we might use local to define two variables, then display those stored values with the reaper.MB statement:

The result would be:

With these ideas, we know how to capture and store information in Lua, and display that information to figure out what our code is doing. Next post: a few key statements from the ReaScript API to capture the name of a Reaper media item.
CHAT GPT?
Several friends suggested using AI to help write my script. And if I was only writing one script, that might have been a quick way to get it done. But my bigger plan was a whole set of scripts for tasks that carry me through significant milestones in my workflow. I didn’t suppose I could build a script ecosystem one AI written script at a time. Also, writing my own Reaper scripts felt more like a power user origin story.
POSTS IN THIS SERIES
Beginner’s Guide to Reaper Script (you are here)
Get Item Name with Reaper Script
Separate an Extension Like .wav from Item Name with Reaper Script
Get File Name with Reaper Script
Rename File with Item Name including Version Control in Reaper Script (pending…)

3 Comments
Leave a CommentTrackbacks