Page 1 of 1
Find out where a command is triggered from
Posted: Sun Mar 12, 2023 2:59 pm
by mrcoollion
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
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
Re: Find out where a command is triggered from
Posted: Sun Mar 12, 2023 3:10 pm
by Klaus
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
Re: Find out where a command is triggered from
Posted: Sun Mar 12, 2023 3:14 pm
by Klaus
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!
Re: Find out where a command is triggered from
Posted: Sun Mar 12, 2023 6:08 pm
by mrcoollion
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

Re: Find out where a command is triggered from
Posted: Sun Mar 12, 2023 7:44 pm
by Klaus
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
Re: Find out where a command is triggered from
Posted: Sun Mar 12, 2023 9:56 pm
by rkriesel
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
Re: Find out where a command is triggered from
Posted: Mon Mar 13, 2023 5:04 pm
by mrcoollion
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.
Re: Find out where a command is triggered from
Posted: Mon Mar 13, 2023 10:45 pm
by SparkOut
It also depends on your stack structure and calling methodology but you might find "the target" provides useful information.
Re: Find out where a command is triggered from
Posted: Tue Mar 14, 2023 10:36 pm
by PaulDaMacMan
You might also use the long form of 'owner' property of objects.
put into the message box yields path to the revMenuBar stack.
Re: Find out where a command is triggered from
Posted: Mon Mar 20, 2023 5:58 pm
by mrcoollion
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