LDCad setEvent, 'run' and passing parameters to macro?


setEvent, 'run' and passing parameters to macro?
#1
Hi Roland,

with 1.7 scripting API in LDCad, is it possible to pass an argument to a macro when it is run? For example, if I have a macro named:
Code:
linkage_parts_select_gf

which has a single argument
Code:
first_call_ai

can a value be passed via the setEvent API e.g.
Code:
macro_lo:setEvent('run', 'linkage_parts_select_gf', '1')

Regards,

David
Reply
RE: setEvent, 'run' and passing parameters to macro?
#2
(2021-09-25, 1:45)David Manley Wrote: with 1.7 scripting API in LDCad, is it possible to pass an argument to a macro when it is run?

Not at the moment.

I kept the callbacks simple (like in Javascript etc).

But the problem in your project can be handled using a global variable, like:

Code:
initTest=true function runTest()   if initTest then     ldc.dialog.runMessage('init')     initTest=false   end     ldc.dialog.runMessage('work') end function register()   local macro=ldc.macro('test')   macro:setEvent('run', 'runTest') end register()

Globals in any script will be preserved until the containing script is reloaded as each script runs in it's own environment.
Reply
RE: setEvent, 'run' and passing parameters to macro?
#3
(2021-09-25, 1:45)David Manley Wrote: can a value be passed via the setEvent API

Side note:
I have been thinking about adding a single extra optional parameter to all the setEvent functions.

But it will be a table name so you could have something like:
Code:
test={   doInit=true,     init=function(self)     print('init')     self.doInit=false   end,   run=function(self)     if self.doInit then       self:init()     end         print('work')   end } function register()   local macro=ldc.macro('test')   macro:setEvent('run', 'run', 'test') end register()

To fake object oriented programming.
Reply
« Next Oldest | Next Newest »



Forum Jump:


Users browsing this thread: 1 Guest(s)