Parameter passing between stacks

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
lcgrs
Posts: 19
Joined: Thu Sep 05, 2013 5:44 pm

Parameter passing between stacks

Post by lcgrs » Sat Jan 10, 2015 12:07 pm

Hi,

On this page I found the explanation about the command dispatch for passing a value to another stack.
I don't find how to catch the parameter in the

put "hello" into SampleField
dispatch SampleField to newstack

on open newstack
-- How can I catch the value of dispatched value???
end open

Any hints?

Thanks!

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Re: Parameter passing between stacks

Post by WaltBrown » Sat Jan 10, 2015 12:17 pm

You need a message receiver in the target stack, as in:

Code: Select all

on Hello
   put "Hello" into fld "fResults"
end Hello
Walt
Walt Brown
Omnis traductor traditor

lcgrs
Posts: 19
Joined: Thu Sep 05, 2013 5:44 pm

Re: Parameter passing between stacks

Post by lcgrs » Sat Jan 10, 2015 1:34 pm

Code: Select all

on Hello
   put "Hello" into fld "fResults"
end Hello
This concerns the sending of the field fResults - or not?
So, how do I make the message receiver in the target stack?

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

Re: Parameter passing between stacks

Post by SparkOut » Sat Jan 10, 2015 1:45 pm

No no, you have despatched the message "hello" to the new stack. In the new stack script you just need a handler to catch the message. So

Code: Select all

on hello
  Answer "this is the response to the message despatched from the first stack"
End hello

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

Re: Parameter passing between stacks

Post by SparkOut » Sat Jan 10, 2015 1:54 pm

or perhaps what you want is the SampleField to contain arguments to use in the destination stack. Something like

Code: Select all

put "hello" into field "SampleField" --would have been typed by the user
dispatch "handleThis" to stack "newstack" with (field "SampleField")
in the newstack stack script

Code: Select all

on handleThis pArgument
  if pArgument is "hello" then
    answer "you passed the argument 'hello' to the new stack"
  else
    answer "the argument" && pArgument && "is not recognised"
  end if
end handleThis

lcgrs
Posts: 19
Joined: Thu Sep 05, 2013 5:44 pm

Re: Parameter passing between stacks

Post by lcgrs » Sat Jan 10, 2015 1:56 pm

SparkOut wrote:or perhaps what you want is the SampleField to contain arguments to use in the destination stack. Something like
Thats it! Thanks! :D

lcgrs
Posts: 19
Joined: Thu Sep 05, 2013 5:44 pm

Re: Parameter passing between stacks

Post by lcgrs » Sat Jan 10, 2015 2:40 pm

SparkOut wrote:

Code: Select all

put "hello" into field "SampleField" --would have been typed by the user
… Execution error at line 2 (Chunk: no such object), char 1 :?
(Strict compilation mode is turned off)

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

Re: Parameter passing between stacks

Post by SparkOut » Sat Jan 10, 2015 3:02 pm

I'm assuming you have a field on your first card called "SampleField"

I'm assuming that you would expect to be able to type something in the field "SampleField" to be used as the argument to pass to the new stack.

I'm assuming you realise that the statement

put "hello" into field "SampleField"

is not necessary if you have such a field that you have typed "hello" (or anything else) into

Post Reply