Hello Guest it is March 29, 2024, 01:34:24 AM

Author Topic: need some lua help  (Read 9256 times)

0 Members and 1 Guest are viewing this topic.

Re: need some lua help
« Reply #10 on: May 03, 2015, 10:48:43 AM »
Sorry, I thought you said they weren't defined yet.  Once they are, you can follow the instructions to access them as you say.

Peter

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need some lua help
« Reply #11 on: May 03, 2015, 03:45:20 PM »
I can find them its just the code needs them available for m code I worked out how to do it for one not all of them to together

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need some lua help
« Reply #12 on: May 03, 2015, 10:11:51 PM »
this is what i have come up with probley wrong

Code: [Select]
function VariableParamFunc(...)
local TS_XPos = 0; local TS_YPos = 0; local TS_Type = 0; local TS_TouchPos = 0; local mInst = 0;
    local inst = mc.mcGetInstance(mInst);
TS_XPos, TS_YPos, TS_Type, TS_TouchPos = select(1, ...);
    if TS_XPos == nil then TS_XPos = "nil"; end
    if TS_YPos == nil then TS_YPos = "nil"; end
    if TS_Type == nil then TS_Type = "nil"; end 
    if TS_TouchPos == nil then TS_TouchPos = "nil"; end
mc.mcCntlSetLastError(  inst,
                            " TS_XPos = " .. tostring( TS_XPos)..
                            " TS_YPos = ".. tostring(TS_YPos)..
                            " TS_Type = ".. tostring(TS_Type)..
                            " TS_TouchPos = ".. tostring(TS_TouchPos));
end

if (mc.mcInEditor() == 1) then
    VariableParamFunc();
    VariableParamFunc(2,3,4);
end

--You can pass as many params as you want, by putting in the function
--variables that get them via the order them come in at.
--this example handles three.
--Scott

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need some lua help
« Reply #13 on: May 04, 2015, 07:42:54 AM »
right this lua is a pita

what I think I need to do is use this

function GetRegister(regname)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))
return mc.mcRegGetValueString(hreg)
end

and have it like this

function GetRegister(TS_XPos)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s, TS_XPos",10))

end

function GetRegister(TS_YPos)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s, TS_Pos",10))

so on

then end with this
return mc.mcRegGetValueString(hreg)
end

it compiles and runs and debugs with no problem

then at top of m1005 put in path to it or not

but when I run m1005 it compiles but does not run as it cant find the Register`s

I have put them in as iregs and gregs that did fa I could find and read them using one of Scott examples this one Quicky Wizard and/or Macro variable value viewer function.

the thing I am getting stuck on is m1005 finding them I meant to put them in a use macro or module.

with what I have put in here how wrong am I

also Scott is there something you or ya bro have posted that is the correct way of doing just pointers please, if I can`t work this out by the end of the week I might ask for the answer

for the time being I will just use the macro b to do tool height probing it works but I would rather use the code in the manual it`s a bit safer 

and i will be doing the first cut with M4 Friday or monday just got to fix a bobo

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: need some lua help
« Reply #14 on: May 04, 2015, 07:47:49 AM »
You may have already done this but,

In the Register plugin, in the "instance" tab, that is where you add your register name and the value of that register.

i.e.
you will have under the "Name" and "Initial Value" columb:
TS_XPos             2.0
TS_YPos             1.5
etc....

Then in your code that you getting those values:

function GetRegister(regname)
   local inst = mc.mcGetInstance()
   local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))
   return mc.mcRegGetValueString(hreg)
end

local TS_XPosVal = tonumber(GetRegister("TS_XPos"));
local TS_YPosVal = tonumber(GetRegister("TS_YPos"));
etc.

Scott
fun times

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need some lua help
« Reply #15 on: May 04, 2015, 08:01:04 AM »
thank`s scott my brains burt for to day I will get back to it tommrow I have done half of that i have put the registers in

then i will do what you have suggested.
« Last Edit: May 04, 2015, 08:03:20 AM by daniellyall »
Re: need some lua help
« Reply #16 on: May 04, 2015, 10:09:34 AM »
I always wondered what is the difference between global registers and instance registers, when to use one or the other, etc ;  i guess most programmers know about that , but is there a simple explanation somewhere for regular users ?

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need some lua help
« Reply #17 on: May 06, 2015, 05:30:44 AM »
this is what I have so far its still not working

local macroname = "m1005"
function GetRegister(regname)


local rc
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))
return mc.mcRegGetValueString(hreg)
end

local TS_XPosVal = tostring(GetRegister("TS_XPos"));
local YPosVal = tostring(GetRegister("TS_YPos"));
local TypeVal = tostring(GetRegister("TS_Type"));
local TouchPosVal = tostring(GetRegister("TS_TouchPos"));
local ProbeHVal = tostring(GetRegister("TS_ProbeH"));
local RetractLVal = tostring(GetRegister("TS_RetractL"));
local DefaultVal = tostring(GetRegister("TS_DefaultL"));


--regval = GetRegister("TS_Type")
--wx.wxMessageBox(regval)

if (mc.mcInEditor() == 1) then
    GetRegister ();
end

I have put them in the Register and can call them using
egval = GetRegister("TS_Type")
wx.wxMessageBox(regval)

I keep getting this
[string "C:\Mach4Hobby\Macros\m1005.mcs"]:34: attempt to call global 'GetRegister' (a nil value)
stack traceback:
   [string "C:\Mach4Hobby\Macros\m1005.mcs"]:34: in function 'm1005'
   [string "C:\Mach4Hobby\Macros\m1005.mcs"]:103: in main chunk


mcLua ERROR: Lua: Error while running chunk

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: need some lua help
« Reply #18 on: May 06, 2015, 08:45:53 AM »
Try this instead:

function m1005()   
   --local macroname = "m1005"
   function GetRegister(regname)
      local rc;
      local inst = mc.mcGetInstance();
      local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname));
      return mc.mcRegGetValueString(hreg);
   end
   local TS_XPosVal = tostring(GetRegister("TS_XPos"));
   local YPosVal = tostring(GetRegister("TS_YPos"));
   local TypeVal = tostring(GetRegister("TS_Type"));
   local TouchPosVal = tostring(GetRegister("TS_TouchPos"));
   local ProbeHVal = tostring(GetRegister("TS_ProbeH"));
   local RetractLVal = tostring(GetRegister("TS_RetractL"));
   local DefaultVal = tostring(GetRegister("TS_DefaultL"));
   --regval = GetRegister("TS_Type");
   --wx.wxMessageBox(regval);
end

if (mc.mcInEditor() == 1) then
    m1005();
end
fun times

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: need some lua help
« Reply #19 on: May 06, 2015, 03:47:15 PM »
I should of been more correct I get this with the m1005 tool height probing from the scripting manual

I keep getting this
[string "C:\Mach4Hobby\Macros\m1005.mcs"]:34: attempt to call global 'GetRegister' (a nil value)
stack traceback:
   [string "C:\Mach4Hobby\Macros\m1005.mcs"]:34: in function 'm1005'
   [string "C:\Mach4Hobby\Macros\m1005.mcs"]:103: in main chunk


mcLua ERROR: Lua: Error while running chunk

having the reg in reg or the macro I can call them but the tool height probing macro cant find them