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

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
brienne
Posts: 1
Joined: Tue Apr 07, 2026 8:27 am
Contact:

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

Post by brienne » Tue Apr 07, 2026 8:31 am

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.

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

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

Post by dunbarx » Tue Apr 07, 2026 2:25 pm

Hmmm.

This is a good one.

Craig

sadovel784
Posts: 1
Joined: Wed May 13, 2026 10:18 am
Contact:

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

Post by sadovel784 » Wed May 13, 2026 10:19 am

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?

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

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

Post by dunbarx » Wed May 13, 2026 2:44 pm

@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

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

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

Post by Klaus » Wed May 13, 2026 4:40 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10102
Joined: Sat Apr 08, 2006 7:05 am
Contact:

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

Post by FourthWorld » Thu May 14, 2026 8:45 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply