Finding objects where the handler is [solved]

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
ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Finding objects where the handler is [solved]

Post by ittarter » Mon Oct 23, 2017 5:28 pm

Hello,

So the way LC works, if a handler is triggered by a handler on a different stack, the second handler looks for objects on the stack of the original handler.

example:

Code: Select all

on mouseup --Card A of Stack A
   send "myHandler" to stack "AnotherStack"
end mouseup

on myHandler --Card A of Stack B
   put "hello" into fld "test"
end myHandler
Result: fld "test" isn't found, because it's on Stack B, not Stack A.

How can I tell Card A of Stack B to look at its own objects instead of the objects of Stack A?
Obviously I can use

Code: Select all

put "hello" into fld "test" of card A of Stack B
but I have hundreds of fields and I would rather keep my code tidier than that.

Putting

Code: Select all

go card A of Stack B
or

Code: Select all

open card A of Stack B
doesn't change anything, unfortunately.

Any ideas?
Last edited by ittarter on Mon Oct 23, 2017 9:14 pm, edited 1 time in total.

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

Re: Finding objects where the handler is

Post by Klaus » Mon Oct 23, 2017 5:53 pm

You could set "the defaultstack" first in your handler:

Code: Select all

on myHandler --Card A of Stack B
   set the defaultstack to "B"
   put "hello" into fld "test"
end myHandler
Is a bit of work, but if you are "sending" lots of things, it is worth the effort.

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

Re: Finding objects where the handler is

Post by dunbarx » Mon Oct 23, 2017 6:35 pm

This might run into trouble if there were three or more stacks worth of "sending. You might, of course, log the stacks as you go.

I run into something like this all the time with subStacks on a current project . My issue is that the mainstack name changes constantly, though its substacks never do. So I simply:

Code: Select all

get fld 1 of the mainStack of this stack
  or
go stack the mainstack of this stack
That sort of thing. in this way each subStack knows who its "parent" is, regardless of any property changes of that parent. Just a variation on a theme.

Craig Newman

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: Finding objects where the handler is

Post by ittarter » Mon Oct 23, 2017 8:36 pm

Klaus wrote:
Mon Oct 23, 2017 5:53 pm
You could set "the defaultstack" first in your handler...
I think this will work well. Thanks, Klaus.
dunbarx wrote:
Mon Oct 23, 2017 6:35 pm
in this way each subStack knows who its "parent" is, regardless of any property changes of that parent. Just a variation on a theme.
Good to know for the future!

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Finding objects where the handler is [solved]

Post by jacque » Tue Oct 24, 2017 5:18 pm

This situation is what the "call" command is for. Try that instead of "send". (Not tested but theoretically should work.)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply