Find out where a command is triggered from

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Find out where a command is triggered from

Post by mrcoollion » Sun Mar 12, 2023 2:59 pm

Hello LC friends,

I might have a bit of a challenge on my hands I hope someone can help me with.

I have moved many commands to SubStacks to have less code in cards that became slow during typing code.
In those stacks, there are

Code: Select all

Put into fld "xyz" of grp "ABC"
statements. Group; ABC is a shared group with behave like background to true .
Because I moved this code to a substack it cannot find field fld "xyz" of grp "ABC" anymore.
I would like to find out from where the command in which this statement is housed is called from so I can use this for refering to the correct card and stack.
Is this possible? Is there a statement I can use to find out where the command was called from?

Kind regards,

Paul

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Find out where a command is triggered from

Post by Klaus » Sun Mar 12, 2023 3:10 pm

Dag Paul,

GROUPS are counted (and looked for) realtive to the current card, BACKGROUNDS relative to the stack.
So make sure all of your groups have unique names, then you can:

Code: Select all

...
put "whatever" into fld "xyz" of BG "ABC"
## BG = abbreviation for background, you guessed :-)
...
without any error.

Best

Klaus

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Find out where a command is triggered from

Post by Klaus » Sun Mar 12, 2023 3:14 pm

Klaus wrote:
Sun Mar 12, 2023 3:10 pm
GROUPS are counted (and looked for) realtive to the current card, BACKGROUNDS
Here an example to make this a bit clearer:

Code: Select all

put the num of groups
## Will return the number of groups on the current card

Code: Select all

put the number of backgrounds
## Will return the number of all groups in the current stack, 
## no matter if these groups have "backgroundbehavior" set or not!

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Find out where a command is triggered from

Post by mrcoollion » Sun Mar 12, 2023 6:08 pm

Thanks for the hint Klaus.

I solved it with the following code.

Code: Select all

   put the mainstack of this stack into tMainStack
   put "123" into fld "xyx" of grp "ABC" of stack tMainStack // BotMessages
This seems to work.
Thanks for taking the time :D

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Find out where a command is triggered from

Post by Klaus » Sun Mar 12, 2023 7:44 pm

I highly recommend to also add the CARD descriptor to be on the safe side!
I guess your mainstack only has one card, right?

Code: Select all

put the mainstack of this stack into tMainStack
put "123" into fld "xyx" of grp "ABC" of CD 1 of stack tMainStack // BotMessages

rkriesel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 118
Joined: Thu Apr 13, 2006 6:25 pm

Re: Find out where a command is triggered from

Post by rkriesel » Sun Mar 12, 2023 9:56 pm

mrcoollion wrote:
Sun Mar 12, 2023 2:59 pm
...
I would like to find out from where the command in which this statement is housed is called from so I can use this for refering to the correct card and stack.
Is this possible? Is there a statement I can use to find out where the command was called from?
...
Hi, Paul.
Yes: see "executionContexts" in the dictionary.
-- Dick

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Find out where a command is triggered from

Post by mrcoollion » Mon Mar 13, 2023 5:04 pm

Thanks,

Great suggestion. Although it is text one can get the button and card id and the stack from which the request for the command has originated from.

Thanks again Dick and Klaus.

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Find out where a command is triggered from

Post by SparkOut » Mon Mar 13, 2023 10:45 pm

It also depends on your stack structure and calling methodology but you might find "the target" provides useful information.

PaulDaMacMan
Posts: 627
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Find out where a command is triggered from

Post by PaulDaMacMan » Tue Mar 14, 2023 10:36 pm

You might also use the long form of 'owner' property of objects.

Code: Select all

 put the long owner of me  
put into the message box yields path to the revMenuBar stack.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Find out where a command is triggered from

Post by mrcoollion » Mon Mar 20, 2023 5:58 pm

Thanks all !
For learning me some new LC stuff.
Used the below statements to get the information i was looking for.

Code: Select all

   put the mainstack of this stack into tMainStackName
   put the id of recent card into tRecentCardID
   put the first line of the recentNames of stack tMainStackName into tRecentCardName
Thanks again and have a LC great day.

Paul

Post Reply

Return to “Talking LiveCode”