BR_SetTakeSourceFromFile missing in Reaper DAW v6.73 - lua

I am evaluating Reaper for automatic music production. "Automatic" like "no human interaction". According to what I have learned in my research, it seems to be possible.
Currently I am stuck. A vital part of my work is importing MIDI files. According to the API one way to do this is the function BR_SetTakeSourceFromFile. When I call it, I get this error:
attempt to call a nil value (field 'BR_SetTakeSourceFromFile')
Which tells me that the method is not defined. I wrote a simple test to verify that:
reaper.ShowConsoleMsg("Reaper version: " .. reaper.GetAppVersion() .. "\n")
if reaper.BR_SetTakeSourceFromFile == nil then
reaper.ShowConsoleMsg("Method BR_SetTakeSourceFromFile does not exist.\n")
else
reaper.ShowConsoleMsg("Method BR_SetTakeSourceFromFile exists.\n")
end
if reaper.BR_SetTakeSourceFromFile2 == nil then
reaper.ShowConsoleMsg("Method BR_SetTakeSourceFromFile2 does not exist.\n")
else
reaper.ShowConsoleMsg("Method BR_SetTakeSourceFromFile2 exists.\n")
end
if reaper.ShowConsoleMsg == nil then
reaper.ShowConsoleMsg("Method ShowConsoleMsg does not exist.\n")
else
reaper.ShowConsoleMsg("Method ShowConsoleMsg exists.\n")
end
The output in the Reaper console is:
Reaper version: 6.73/macOS-arm64
Method BR_SetTakeSourceFromFile does not exist.
Method BR_SetTakeSourceFromFile2 does not exist.
Method ShowConsoleMsg exists.
I am sure that I missed something here. Any help would be appreciated.
I called the method BR_SetTakeSourceFromFile and expected it to work as specified in the documentation.

It turns out you just need to install the "SWS extensions". Case closed!

Related

Glua error "attempt to call method 'GetPlayerVisible' (a nil value)"

I personally don't know how a built in function can be indexed as "nil" butthis error appeared and it haulted my nextbot's movement. heres my code that is causing this
if (!self:GetPlayerVisible() and chasing_timer > chasing_time) then
self.stopchasing = true
self.enraged = false
print("Chase stopped")
print("Increasing escaped chases count, new:", self.escapedchases)
self.escapedchases = self.escapedchases + 1
end
I tried replacing the "!" with "not" but it did nothing.
I don't know what self is but that table does not contain an element GetPlayerVisible. Hece you may not call it. Calling nil values doesn't make sense.
Ask yourself why you think this function exists. Typical reasons are typos, indexing the wrong table or not having implemented a function yet.
To avoid this error you basically have two options. Make sure you call something that exists, or don't call it.

Hammerspoon hs.application:kill() not callable

Trying to get Hammerspoon to quit (kill) the Music app in OS X whenever it opens. (This application has been installed by Apple in such a way as to make it very difficult to alter and it launches whenever a bluetooth device is connected. Annoying bloatware, basically.) So, I cribbed this from the Hammerspoon "Getting started" page https://www.hammerspoon.org/go/...
function applicationWatcher(appName, eventType, appObject)
if (eventType == hs.application.watcher.launched) then
if (appName == "Music") then
hs.application:kill()
end
end
end
appWatcher = hs.application.watcher.new(applicationWatcher)
appWatcher:start()
This correctly responds to the Music app being launched, but it errors out like so... ERROR: LuaSkin: hs.application.watcher callback: /Users/seancamden/.hammerspoon/init.lua:142: method 'kill' is not callable (a nil value)
How I can make this method callable? Or, what is the right way to do this?
https://www.hammerspoon.org/docs/hs.application.watcher.html
https://www.hammerspoon.org/docs/hs.application.html#kill
your code is pretty much right, there is only one mistake. You used the global module hs.application and tried to call an object method :kill() from it. You would have to instantiate a new object first to be able to call it's kill method. For example: hs.application.get(appName):kill().
However, the watcher already provides you with the application object that called the function as appObject. So appObject:kill() is what you are looking for.
function applicationWatcher(appName, eventType, appObject)
if (eventType == hs.application.watcher.launched) then
if (appName == "Music") then
appObject:kill()
end
end
end
appWatcher = hs.application.watcher.new(applicationWatcher)
appWatcher:start()
Tested here on MacOS BigSur

How to determine if sysdig field exists or handle error if it doesn't

I'm using Sysdig to capture some events and have a small chisel (LUA script) to capture and format the events as necessary. On the on_init() I'm requesting fields like so :
f_field = chisel.request_field("<field>")
My question is how can I check if a field exists before requesting it? I'm going to use a new field only just released on 0.24.1 but ideally I'd like my chisel to continue to work on older versions of sysdig without this field. I've tried wrapping the call to chisel.request_field in a pcall() like so :
ok, f_field = pcall(chisel.request_field("<field>"))
and even implementing my own "get_field" function :
function get_field(field)
ok, f = pcall(chisel.request_field(field))
if ok then return f else return nil end
end
f_field = get_field("<field>")
if f_field ~= nil then
-- do something
end
but the error ("chisel requesting nonexistent field <field>") persists.
I can't see a way to check if a field exists but I can't seem to handle the error either. I really don't want multiple versions of my scripts if possible.
Thanks
Steve H
You're almost there. Your issue is in how you're using pcall. Pcall takes a function value and any arguments you wish to call that function with. In your example you're passing the result of the request_field function call to pcall. Try this instead..
ok, f = pcall(chisel.request_field, "field")
pcall will call the chisel method with your args in a protected mode and catch any subsequent errors.

Checking if an instance *doesn't* exist -> "Not a valid member"

"checkin is not a valid member of PlayerGui" at line 2
function onClick(plr)
if game.Players[plr.Name].PlayerGui.checkin ~= nil then
print('player already has gui')
else
if game.ServerStorage.Players[plr.Name].Value == 0 then
local gui = game.ServerStorage.GUIs.checkin:Clone()
gui.Parent = plr.PlayerGui
print('fresh gui being handed to '.. plr.Name)
end
end
end
script.Parent.ClickDetector.MouseClick:connect(onClick)
If a member doesn't exist on an instance, Roblox will immediately throw an error.
If you're not sure if a child of a given name exists, use :FindFirstChild(name). Rather than throw an error, it just returns nil.
Note that MouseClick already gives a player, so doing game.Players[plr.Name] is really redundant.
if plr.PlayerGui:FindFirstChild("checkin") then
It's best practice to not handle GUIs on the Server. Instead, you can communicate to LocalScripts what they need to show using RemoteFunctions/RemoteEvents.

Checking if a table has been created not working

Using the code:
function createNewBody(name,mass)
if not world.body[name]==nil then
print("This body has already been created. Maybe you meant to update it's values?\n")
else
world.body[name]={mass=m,x=0,y=0,xAccel=0,yAccel=0,xR=0,yR=0,properties={gaseous=false,texture=""}}
world.bodies=world.bodies+1
end
end
This code shows no errors, but when I bind createNewBody(moon,1.622) to a key and then use it, it lets me spam the key without showing the error message.
And, yes, I have defined world.bodies and world.body
not world.body[name]==nil is parsed as (not world.body[name])==nil. Since the result of not is a boolean, it is never nil.
Try not(world.body[name]==nil) or world.body[name]~=nil.

Resources