Hello Guest it is March 28, 2024, 02:10:56 PM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - rrc1962

61
Mach4 General Discussion / Re: Using Modules
« on: May 30, 2016, 04:42:23 PM »
First, thanks so much for your help.  It's all working now, but I'm not sure why.  I ended up re-writing the module in question from scratch and it worked.  I couldn't find a typo in the one that didn't or any other reason for it to fail.  Maybe a hidden character?  Also figured out that you have to restart M4 for any changes to a module to take effect.

62
Mach4 General Discussion / Re: Using Modules
« on: May 30, 2016, 02:38:42 PM »
Lets say I create the same class with a slight twist...If I say message = require "myClass" and call message.test() it should return a message box saying 'Nothing to see here'.  We pass 'Nothing' to test2(), it then takes that argument and concatenates ' to see here', then returns the result back to the message box.  Shouldn't this work?

The problem isn't accessing test() from outside.  Problem is accessing test2() from within test().  They are defined within the same module, yet lua doesn't seem to think that test2() exists.

Code: [Select]
local myClass = {}

function myClass.test()
    wx.wxMessageBox(test2('Nothing'))
end

function test2(str)
    str = str .. ' to see here'
    return str
end

return myClass

63
Mach4 General Discussion / Re: Using Modules
« on: May 29, 2016, 11:16:30 PM »
When I load the module, I call sw = require(MduleName).  I think when I call getHeader(), I need to call sw.getHeader().  Sounds like a good start tomorrow.

64
Mach4 General Discussion / Re: Capturing errors
« on: May 29, 2016, 10:47:21 PM »
Yes, but how do I capture the actual runtime error that caused to script to fail?

65
Mach4 General Discussion / Re: Using Modules
« on: May 29, 2016, 10:25:05 PM »
Arrrg...So now I'm just trying to call a function from another function within the module and I get this...

Code: [Select]
C:\Mach4Hobby\Profiles\Mach4Mill\Modules\ShapeWizard.lua:45: attempt to call global 'getHeader' (a nil value)
stack traceback:
C:\Mach4Hobby\Profiles\Mach4Mill\Modules\ShapeWizard.lua:45: in function 'Circle1'
[string "C:\Users\Richard\AppData\Local\Temp\le221E.mc..."]:9: in main chunk

This is the line that generates the error...

Code: [Select]
    wx.wxMessageBox(getHeader() .. getStart('0', '50') .. getStop('0') .. getEnd())
This is getHeader()

Code: [Select]
function getheader()
    gcode1 = 'G20\n'
    gcode1 = gcode1 .. 'G90\n'
    gcode1 = gcode1 .. 'G91.1\n'
    gcode1 = gcode1 .. 'M1102\n'
    gcode1 = gcode1 .. 'M1000\n'
    return gcode1
end

66
Mach4 General Discussion / Re: Using Modules
« on: May 29, 2016, 09:31:02 PM »
OK...It's working....And here's why it wasn't.  The button script was never executing.  This has happened many times.  When I press a button nothing happens.  You assume the script has an error and commence to chase it down the rabbit hole, just to find that the script is not running.

I started out this morning with the button script on the Left Up Script.  Remembering all the trouble I've had with broken buttons, I moved the script to Left Down early this afternoon.  Never had two broken button events, but third time is a charm.  I moved it to Clicked and it all works.

67
Mach4 General Discussion / Re: Using Modules
« on: May 29, 2016, 08:59:14 PM »
Found a problem in the button script.  I had theFunction(), not M.theFunction().

I can now cycle through the code in the editor and when it hits the line M.theFunction(), it goes to the function and does nothing.  I should be displaying a message box.  Running it outside the editor doesn't do anything either.  Am I trying to do something here that can't be done in a function?  Is it a scope issue?

Correction...It works in the editor.  The message box was displaying in the background.  Does not work outside the editor though.

68
Mach4 General Discussion / Capturing errors
« on: May 29, 2016, 08:48:05 PM »
Is there a way to capture and display errors in a button script.  Problem is that when the script fails, it just doesn't do anything as if it never ran.  The reason why it failed would be immensely helpful.

69
Mach4 General Discussion / Re: Using Modules
« on: May 29, 2016, 08:38:20 PM »
Poppabear has this in the screen load script...

Code: [Select]
package.path = "./?.lua;c:/Mach4Hobby/Modules/?.mcc;" --where the module file is.   
M = require "Module1"

Daz has this

Code: [Select]
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)
package.path = path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.lua;"
M = require "Module1"

Poppabear is referencing .mcc files where Daz references .lua files.  Everything I'm digging up tells me that the module should be a .lua file.

70
Mach4 General Discussion / Re: Using Modules
« on: May 29, 2016, 08:27:49 PM »
What he did contradicts what Daz said.  Poppabear is using an.mcc file.  Daz said to use a .lua file, which jives with basic lua documentation. I'm surprised there are not enough people using modules to warrant a blurb in the scripting manual on how to use them.  They talk about modules and how useful they are, but nothing on how to use them.