|
|
|
03-02-2017, 08:12 AM
|
#1
|
Human being with feelings
Join Date: Nov 2015
Location: Switzerland
Posts: 1,966
|
Scripts with custom actions?
Hi,
I'm quite new to scripting (just a little background of JavaScript and jQuery), especially to Reaper scripts.
I know that to perform actions I need to use Main_OnCommand(actionID, 0), but I've noticed that if I copy a custom action's ID, I get an error when I try to save the script.
Am I doing something wrong or custom actions can't be performed via ReaScripts?
Last edited by DaveKeehl; 03-02-2017 at 08:19 AM.
|
|
|
03-02-2017, 08:20 AM
|
#2
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
For custom actions and scripts you need to get action ID that Reaper has the script's GUID - "_ah4wp93pa98uf1awhatever" assigned to.
This is how I do it in Lua, along with some error checking:
Code:
-- 'act' is the action/script ID in a string
-- Scripts and custom actions all use the same format for their GUID,
-- so you just need to see if the string starts with a '_'
if string.sub(act, 1, 1) == "_" then
act = reaper.NamedCommandLookup(act)
end
-- Not strictly necessary, but Lua doesn't always like it when you try
-- to use a string as a number
act = tonumber(act)
-- Make sure that:
-- a) tonumber() worked, and
-- b) we have a useable action ID
if act and act > 0 then
reaper.Main_OnCommand(act, 0)
end
|
|
|
03-02-2017, 08:36 AM
|
#3
|
Human being with feelings
Join Date: Nov 2015
Location: Switzerland
Posts: 1,966
|
Sorry I'm not sure where I have to put the ID (_93e0a9b2d00c0b4ebc0e93ae2ba39519) or the action name
|
|
|
03-02-2017, 08:48 AM
|
#4
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Just add this before the code above:
Code:
local act = "_93e0a9b2d00c0b4ebc0e93ae2ba39519"
|
|
|
03-02-2017, 08:51 AM
|
#5
|
Human being with feelings
Join Date: Nov 2015
Location: Switzerland
Posts: 1,966
|
Oh ok. So the whole bunch of code would be:
local act = "_93e0a9b2d00c0b4ebc0e93ae2ba39519"
if string.sub(act, 1, 1) == "_" then
act = reaper.NamedCommandLookup(act)
end
act = tonumber(act)
if act and act > 0 then
reaper.Main_OnCommand(act, 0)
end
Correct ?
|
|
|
03-02-2017, 08:54 AM
|
#6
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Correct.
|
|
|
03-02-2017, 09:13 AM
|
#7
|
Human being with feelings
Join Date: Nov 2015
Location: Switzerland
Posts: 1,966
|
Ok thanks and how can I create a for cycle?
edit: well it doesn't really matter... I can look it up online
Last edited by DaveKeehl; 03-02-2017 at 09:32 AM.
|
|
|
03-02-2017, 12:51 PM
|
#8
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
In case you haven't found it yet (you probably have), a basic for loop in Lua looks like this:
Code:
for i = 1, 10 do
reaper.ShowConsoleMsg("i = "..i.."\n")
end
You can also provide a third number to use as the 'step' amount:
Code:
for i = 10, 1, -1 do
...
end
for i = 1, 10, 0.5 do
...
end
Also useful is being able to exit the loop early:
Code:
for i = 1, 10 do
reaper.ShowConsoleMsg("i = "..i.."\n")
if i == 8 then
break
end
end
|
|
|
03-02-2017, 02:09 PM
|
#9
|
Human being with feelings
Join Date: Nov 2015
Location: Switzerland
Posts: 1,966
|
Yes, I had found something but I didn't have the time to sit down and learn how to code in Lua. Thanks anyway, that's very helpful.
My goal is to create a script that can perform an action as many times as the number of the tracks. In JS would be something like this (using a bit of the Reaper API):
Code:
var trackNumber = integer reaper.GetNumTracks()
for (var i = 0; i < trackNumber; i++) {
custom action();
}
|
|
|
03-02-2017, 02:24 PM
|
#10
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Easy peasy:
Code:
local trackNumber = reaper.GetNumTracks()
for i = 0, (trackNumber - 1) do
custom_action()
end
|
|
|
03-02-2017, 02:55 PM
|
#11
|
Human being with feelings
Join Date: Nov 2015
Location: Switzerland
Posts: 1,966
|
thanks!
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 09:09 AM.
|