Passing parameters from one handler to another

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
athelene
Posts: 18
Joined: Sun Jul 26, 2015 9:19 pm

Passing parameters from one handler to another

Post by athelene »

I am struggling to figure out why I'm not able to pass a parameter from one handler to another. I do this successfully with others, but can't seem to figure out the problem with this one. The first handler looks essentially like this:

on MyHandlerA
loadLinks, gSelectedItem
end myHandlerA


In the IDE, I put a break just before and after this to check the variable gSelectedItem and it is correct.

The receiving handler looks like this:

on loadLinks, gSelectedItem
answer "gSelectedItem is: " & gSelectedItem
end loadLinks


At this point, gSelectedItem is empty. The variable has been declared as a global variable before either handler. Can you please point me in the right direction to figure out why this variable isn't being properly passed to the second handler?
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Passing parameters from one handler to another

Post by FourthWorld »

Remove the comma.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Passing parameters from one handler to another

Post by dunbarx »

What Richard said.

But you will indeed need commas for any subsequent parameters:

yourHandler param1,param2,param3...

Craig Newman
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Passing parameters from one handler to another

Post by Klaus »

The variable has been declared as a global variable before either handler.
This is not neccessary, if you only pass the variable(s) as parameter(s) to other handlers!
athelene
Posts: 18
Joined: Sun Jul 26, 2015 9:19 pm

Re: Passing parameters from one handler to another

Post by athelene »

Grrr! No comma, of course. I should have taken a break before I submitted this. Maybe I would have seen it for myself. Thank you so much.

Athelene
athelene
Posts: 18
Joined: Sun Jul 26, 2015 9:19 pm

Re: Passing parameters from one handler to another

Post by athelene »

Klaus,

Thank you for your reply. I'd like to follow up on your answer. I have always thought that global variables should work as you stated, without having to be passed from one handler to another. But I find that it doesn't work for me. I'm guessing that means that I'm doing something wrong with setting up my global variables. The code I've been using is simply:

global gMyVariable

Is there some other criteria I need to set or do they need to be established in some particular place? Any other thoughts as to why I am not getting the expected behavior from my global variables?
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Passing parameters from one handler to another

Post by dunbarx »

LC requires that global variables be declared in every script they are used, and ABOVE and handler within that script that might need it. This is different than the way some other languages use globals.

This is a common discussion. The next step is to learn about and consider using custom properties instead. These need only be set once, and are thereafter available everywhere. Further, they survive sessions.

Craig Newman
Post Reply