Page 1 of 1
calling a handler as a variable
Posted: Sun Feb 09, 2014 4:48 pm
by adventuresofgreg
Hi: referencing the name of a handler as a variable won't work. Any idea how to accomplish this?
ie the following won't work, but gives you an example of what I'm trying to do:
-------
put "runThisSystem" into myHandlerName
if this then myHandlerName (var1,var2)
-------
When I run "myHandlerName", I actually want to run "runThisSystem"
Re: calling a handler as a variable
Posted: Sun Feb 09, 2014 5:26 pm
by Dixie
Code: Select all
on mouseUp
put "runThisSystem" into myHandlerName
if myHandlerName = "runThisSystem" then
runThisSystem
end if
end mouseUp
on runThisSystem
beep
end runThisSystem
strange...
Re: calling a handler as a variable
Posted: Sun Feb 09, 2014 5:37 pm
by Klaus
Hi Greg,
just DO it
...
put "runThisSystem" into myHandlerName
do myHandlerName
...
Best
Klaus
Re: calling a handler as a variable
Posted: Sun Feb 09, 2014 6:45 pm
by adventuresofgreg
Klaus - oops, it's a FUNCTION, not a handler. Sorry. It's like this:
...
put "runThisSystem" into myFUNCTIONname
put myFUNCTIONname (var1,var2,var3) into whatever
...
Re: calling a handler as a variable
Posted: Sun Feb 09, 2014 6:49 pm
by adventuresofgreg
Hi Dixie: Sorry, it was a FUNCTION, not a handler. Yes your solution would work, but for other reasons, I can't run a bunch of if scenarios. The user would type the name of the system to run in a field, and the script should just find the function in the stack scripts and run it. Every time I add a new function, I don't want to add a corresponding "if then". you know?
Dixie wrote:Code: Select all
on mouseUp
put "runThisSystem" into myHandlerName
if myHandlerName = "runThisSystem" then
runThisSystem
end if
end mouseUp
on runThisSystem
beep
end runThisSystem
strange...
Re: calling a handler as a variable
Posted: Sun Feb 09, 2014 7:10 pm
by dunbarx
Hi.
Like this?
Code: Select all
on mouseUp
put any item of "A,B,C" into var
put "runThisSystem" && var into myHandlerName
answer runThisSystem(var)
end mouseUp
function runThisSystem var
return "You chose" && var
end runThisSystem
Craig
Re: calling a handler as a variable
Posted: Sun Feb 09, 2014 8:09 pm
by Klaus
dunbarx wrote:Hi.
Like this?
Code: Select all
on mouseUp
put any item of "A,B,C" into var
put "runThisSystem" && var into myHandlerName
answer runThisSystem(var)
end mouseUp
function runThisSystem var
return "You chose" && var
end runThisSystem
Craig
Value can help here:
...
put "runThisSystem" into myFUNCTIONname
put VALUE("myFUNCTIONname (var1,var2,var3)") into whatever
...
tested and works!
Best
Klaus
Re: calling a handler as a variable
Posted: Sun Feb 09, 2014 8:41 pm
by adventuresofgreg
That's it Klaus. I've never used VALUE before. Thanks!