11
Mach4 General Discussion / How do I call a function in a module from a screen button?
« on: March 08, 2024, 07:46:04 PM »
Like the title states I'm trying to call a function that I have placed in a module from a button I've added to a screen.
I plan to add several functions and but even though I've copied examples that I've found they do not work. So far my code is really simple it looks like:
Button: (Clicked Script event)
In folder C:\Mach4Hobby\Profiles\AXYZ\Macros
I added File: Load_Modules.mcs, all of the code looks like:
In Folder C:\Mach4Hobby\Profiles\AXYZ\Modules
I added File: Test.lua, all of the code looks like:
When I press the button I get the error:
Lua: Error while running chunk
c:\Mach4Hobby\ScreenScript.lua:854: attempt to call a nil value (global 'PrintVal')
stack traceback:
c:\Mach4Hobby\ScreenScript.lua:854: in function 'BUTTON_Test_Clicked_Script'
Can anyone tell me what I am doing wrong?
All of the files compile. The best I can figure out is that the screenscript.lua doesn't know anything about the modules, but according to the documentation my Load_modules.mcs file should load this.
I have made sure to delete the Load_Modules.mcc file and restart mach to recompile it after making changes to that file.
I plan to add several functions and but even though I've copied examples that I've found they do not work. So far my code is really simple it looks like:
Button: (Clicked Script event)
Code: [Select]
PrintVal("123")
In folder C:\Mach4Hobby\Profiles\AXYZ\Macros
I added File: Load_Modules.mcs, all of the code looks like:
Code: [Select]
package.path = wx.wxGetCwd() .. "\\Profiles\\AXYZ\\Modules\\Test.lua"
package.loaded.Test = nil
require "Test"
In Folder C:\Mach4Hobby\Profiles\AXYZ\Modules
I added File: Test.lua, all of the code looks like:
Code: [Select]
function PrintVal(val)
wx.wxMessageBox("Current val="..tostring(val))
end
When I press the button I get the error:
Lua: Error while running chunk
c:\Mach4Hobby\ScreenScript.lua:854: attempt to call a nil value (global 'PrintVal')
stack traceback:
c:\Mach4Hobby\ScreenScript.lua:854: in function 'BUTTON_Test_Clicked_Script'
Can anyone tell me what I am doing wrong?
All of the files compile. The best I can figure out is that the screenscript.lua doesn't know anything about the modules, but according to the documentation my Load_modules.mcs file should load this.
I have made sure to delete the Load_Modules.mcc file and restart mach to recompile it after making changes to that file.