Page 1 of 1

Parameter passing between stacks

Posted: Sat Jan 10, 2015 12:07 pm
by lcgrs
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!

Re: Parameter passing between stacks

Posted: Sat Jan 10, 2015 12:17 pm
by WaltBrown
You need a message receiver in the target stack, as in:

Code: Select all

on Hello
   put "Hello" into fld "fResults"
end Hello
Walt

Re: Parameter passing between stacks

Posted: Sat Jan 10, 2015 1:34 pm
by lcgrs

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?

Re: Parameter passing between stacks

Posted: Sat Jan 10, 2015 1:45 pm
by SparkOut
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

Re: Parameter passing between stacks

Posted: Sat Jan 10, 2015 1:54 pm
by SparkOut
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

Re: Parameter passing between stacks

Posted: Sat Jan 10, 2015 1:56 pm
by lcgrs
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

Re: Parameter passing between stacks

Posted: Sat Jan 10, 2015 2:40 pm
by lcgrs
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)

Re: Parameter passing between stacks

Posted: Sat Jan 10, 2015 3:02 pm
by SparkOut
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