Passing parameters from one handler to another
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Passing parameters from one handler to another
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?
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?
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Passing parameters from one handler to another
Remove the comma.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Passing parameters from one handler to another
What Richard said.
But you will indeed need commas for any subsequent parameters:
yourHandler param1,param2,param3...
Craig Newman
But you will indeed need commas for any subsequent parameters:
yourHandler param1,param2,param3...
Craig Newman
Re: Passing parameters from one handler to another
This is not neccessary, if you only pass the variable(s) as parameter(s) to other handlers!The variable has been declared as a global variable before either handler.
Re: Passing parameters from one handler to another
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
Re: Passing parameters from one handler to another
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?
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?
Re: Passing parameters from one handler to another
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
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