calling a handler as a variable

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

calling a handler as a variable

Post by adventuresofgreg » Sun Feb 09, 2014 4:48 pm

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"

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: calling a handler as a variable

Post by Dixie » Sun Feb 09, 2014 5:26 pm

Code: Select all

on mouseUp
   put "runThisSystem" into myHandlerName
   
   if myHandlerName = "runThisSystem" then
      runThisSystem
   end if
end mouseUp

on runThisSystem
   beep
end runThisSystem
strange...

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: calling a handler as a variable

Post by Klaus » Sun Feb 09, 2014 5:37 pm

Hi Greg,

just DO it :D
...
put "runThisSystem" into myHandlerName
do myHandlerName
...

Best

Klaus

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: calling a handler as a variable

Post by adventuresofgreg » Sun Feb 09, 2014 6:45 pm

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
...

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: calling a handler as a variable

Post by adventuresofgreg » Sun Feb 09, 2014 6:49 pm

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...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: calling a handler as a variable

Post by dunbarx » Sun Feb 09, 2014 7:10 pm

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

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: calling a handler as a variable

Post by Klaus » Sun Feb 09, 2014 8:09 pm

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
:D :D :D :D

Value can help here:
...
put "runThisSystem" into myFUNCTIONname
put VALUE("myFUNCTIONname (var1,var2,var3)") into whatever
...
tested and works!


Best

Klaus

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: calling a handler as a variable

Post by adventuresofgreg » Sun Feb 09, 2014 8:41 pm

That's it Klaus. I've never used VALUE before. Thanks!

Post Reply