Page 1 of 1

Why does my LiveCode script fail to properly update and pass data between stacks using send and dispatch

Posted: Tue Apr 07, 2026 8:31 am
by brienne
Hi everyone, I’m working on a multi-stack LiveCode project where I’m trying to pass data between a mainstack and a substack using both `send` and `dispatch`, but I’m running into inconsistent behavior where the receiving stack either doesn’t update its fields or throws an execution error depending on how the message is triggered; for example, I’m using code like `send "updateData tValue" to stack "SubStackA" in 0 millisecs` and also testing `dispatch "updateData" to stack "SubStackA" with tValue`, but the handler sometimes isn’t recognized or the variable scope seems lost when the message arrives, especially after opening and closing stacks dynamically, so I’m wondering if this is related to message path issues, timing (async vs sync), or how LiveCode handles variable context across stacks, and what would be the correct pattern to reliably pass and update data between stacks in a more complex app structure.

Re: Why does my LiveCode script fail to properly update and pass data between stacks using send and dispatch

Posted: Tue Apr 07, 2026 2:25 pm
by dunbarx
Hmmm.

This is a good one.

Craig

Re: Why does my LiveCode script fail to properly update and pass data between stacks using send and dispatch

Posted: Wed May 13, 2026 10:19 am
by sadovel784
It sounds like a message path and scope issue more than a timing one. Have you verified that the handler exists in the substack’s script (not just the mainstack) and that you’re passing parameters explicitly rather than relying on local variables, especially after dynamically opening stacks?

Re: Why does my LiveCode script fail to properly update and pass data between stacks using send and dispatch

Posted: Wed May 13, 2026 2:44 pm
by dunbarx
@Sadovel784.

You sound real. My post implied that the OP was not.

I have been wrong about that sort of thing. I am very interested in hearing back from either of you.

Craig

Re: Why does my LiveCode script fail to properly update and pass data between stacks using send and dispatch

Posted: Wed May 13, 2026 4:40 pm
by Klaus
I highly doubt that there may be any message path issues when sending or dispatching data from one stack to another one in the SAME stack file! Same for the SCOPE of the passed variable.

@brienne
Do you get any errors or whatever in LC when it fails using "send" or "dispatch"?

You could also try using a custom property for your transfer of data between stack. I never had problem with this technique!

Do like this:
1. Make sure "SubStackA" has the handler "updateData" in its stack script.
2. Create this handler in the stack script of SubStackA"

Code: Select all

setprop data2update tData
  updateData tData
end data2update
3. Then pass the data to that stack from another stack like:

Code: Select all

...
## Fill a variable with the update data and set the custom 
## property of the target stack to that variable
set the data2update of stack "SubStackA" to tData
...
This will "trigger" the above mentioned SETPROP handler to "do the right thing". :-)

That should do what you want, please try and report back.

Best

Klaus

Re: Why does my LiveCode script fail to properly update and pass data between stacks using send and dispatch

Posted: Thu May 14, 2026 8:45 pm
by FourthWorld
Hard to follow the block of text. A simple example stack exhibiting the issue will help us resolve it in seconds. I suspect it has to do with variable names quoted in a way that causes them to be seen instead as strings, but I'm just guessing. An example stack will turn guessing into a solution quickly.