Hello Guest it is November 30, 2020, 04:05:20 PM

Author Topic: Passing a value in function call  (Read 156 times)

0 Members and 1 Guest are viewing this topic.

Offline bcoop

*
  •  44 44
    • View Profile
Passing a value in function call
« on: March 13, 2020, 09:06:04 AM »
New to programming lua, need some basic help with passing a parm to a function, 
trying to set the JogRatePercent by calling a function and passing the float value i want to set in the JogRatePercent.
here is what i have which is not working. 
any help would be appreciated.

function JogRatePercent(percent) --This function sets the jog rate

wx.wxMessageBox(percent)
   scr.SetProperty("droJogRate", "Value", 'percent')
end

--------------------------------------------------------------------------------------
--the code below works but without passing the value to the function.


function JogRate1Percent() --This function sets the jog rate to 1 %

   scr.SetProperty("droJogRate", "Value", "1.0")
end
JogRate1Percent()
Bob
Re: Passing a value in function call
« Reply #1 on: March 13, 2020, 11:26:15 AM »
The issue is that you have single quotation marks around percent. Lua recognises anything enclosed with " " or ' ' as strings so its trying to set it to the string 'percent'. If passing the param to the function as a number you'll have to use the tostring() function as scr.SetProperty requires strings.

Try this..
Code: [Select]
function JogRatePercent(percent) --This function sets the jog rate
   scr.SetProperty("droJogRate", "Value", tostring(percent))
end

Ideally you should use the API call mc.mcJogSetRate rather than using the scr call. If you haven't found the list of these API's yet check inside the Docs folder in the Mach4 directory, Mach4CoreAPI.chm.

wx.wxMessageBox() also only accepts strings.

Offline bcoop

*
  •  44 44
    • View Profile
Re: Passing a value in function call
« Reply #2 on: March 13, 2020, 11:58:19 AM »
Works!   Thank you very much SwitftyJ,  much appreciated.
Bob