Call a function on another card

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Call a function on another card

Rick Harrison via use-livecode
Hi,

I’m reading on
http://lessons.livecode.com/m/4071/l/11787-how-to-call-a-function-or-command-in-another-object

this:
put value("myFunction(hello, world)", group "myGroup" of card "myCard") into tResult

I want to use a variable as a parameter instead of “hello, world” as in the page example.

These don’t work:
put value(“getPageNumber (tID)", card "MITA" of stack "MITA") into tResult
put value("getPageNumber" & (tID), card "MITA" of stack "MITA") into tResult

What do I do?

Peter Bogdanoff
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Call a function on another card

Rick Harrison via use-livecode
Will this work for you?
dispatch function "myFunction" to card "myCard"

put the result into tResult

Parameters can also be passed using the "with" extension. Unlike the
"call", "send" and "value" handlers, the parameters are sent directly to
the target handler, rather than being extracted from the string used to
call the handler. This negates the need to surround our parameters in
quotes and also allows us to pass arrays

On Thu, Feb 23, 2017 at 1:32 PM, Peter Bogdanoff via use-livecode <
[hidden email]> wrote:

> Hi,
>
> I’m reading on
> http://lessons.livecode.com/m/4071/l/11787-how-to-call-a-
> function-or-command-in-another-object
>
> this:
> put value("myFunction(hello, world)", group "myGroup" of card "myCard")
> into tResult
>
> I want to use a variable as a parameter instead of “hello, world” as in
> the page example.
>
> These don’t work:
> put value(“getPageNumber (tID)", card "MITA" of stack "MITA") into tResult
> put value("getPageNumber" & (tID), card "MITA" of stack "MITA") into
> tResult
>
> What do I do?
>
> Peter Bogdanoff
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Call a function on another card

Rick Harrison via use-livecode
Yes, thank you, that works. I used:

dispatch function "getPageNumber" to card "MITA" of stack "MITA" with tID

What came back was in “the result”

“it” contained “handled”

pb

On Feb 23, 2017, at 12:54 PM, Mike Bonner via use-livecode <[hidden email]> wrote:

> Will this work for you?
> dispatch function "myFunction" to card "myCard"
>
> put the result into tResult
>
> Parameters can also be passed using the "with" extension. Unlike the
> "call", "send" and "value" handlers, the parameters are sent directly to
> the target handler, rather than being extracted from the string used to
> call the handler. This negates the need to surround our parameters in
> quotes and also allows us to pass arrays
>
> On Thu, Feb 23, 2017 at 1:32 PM, Peter Bogdanoff via use-livecode <
> [hidden email]> wrote:
>
>> Hi,
>>
>> I’m reading on
>> http://lessons.livecode.com/m/4071/l/11787-how-to-call-a-
>> function-or-command-in-another-object
>>
>> this:
>> put value("myFunction(hello, world)", group "myGroup" of card "myCard")
>> into tResult
>>
>> I want to use a variable as a parameter instead of “hello, world” as in
>> the page example.
>>
>> These don’t work:
>> put value(“getPageNumber (tID)", card "MITA" of stack "MITA") into tResult
>> put value("getPageNumber" & (tID), card "MITA" of stack "MITA") into
>> tResult
>>
>> What do I do?
>>
>> Peter Bogdanoff
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Call a function on another card

Rick Harrison via use-livecode
When I encounter situations like these, I begin to ask myself why the handler is in a card script. If it needs to be accessible from other cards, it should probably be moved to the stack script, or put into a button and inserted into front or back. I have 3 buttons I use for this effect: Utilities, Validations and Database Functions. Utilities and Database functions I insert into back. The validations I insert into front in case I want to intercept things like openField or selectionChanged and do things before passing them on.

Bob S


> On Feb 23, 2017, at 13:21 , Peter Bogdanoff via use-livecode <[hidden email]> wrote:
>
> Yes, thank you, that works. I used:
>
> dispatch function "getPageNumber" to card "MITA" of stack "MITA" with tID
>
> What came back was in “the result”
>
> “it” contained “handled”
>
> pb
>
> On Feb 23, 2017, at 12:54 PM, Mike Bonner via use-livecode <[hidden email]> wrote:
>
>> Will this work for you?
>> dispatch function "myFunction" to card "myCard"
>>
>> put the result into tResult
>>
>> Parameters can also be passed using the "with" extension. Unlike the
>> "call", "send" and "value" handlers, the parameters are sent directly to
>> the target handler, rather than being extracted from the string used to
>> call the handler. This negates the need to surround our parameters in
>> quotes and also allows us to pass arrays
>>
>> On Thu, Feb 23, 2017 at 1:32 PM, Peter Bogdanoff via use-livecode <
>> [hidden email]> wrote:
>>
>>> Hi,
>>>
>>> I’m reading on
>>> http://lessons.livecode.com/m/4071/l/11787-how-to-call-a-
>>> function-or-command-in-another-object
>>>
>>> this:
>>> put value("myFunction(hello, world)", group "myGroup" of card "myCard")
>>> into tResult
>>>
>>> I want to use a variable as a parameter instead of “hello, world” as in
>>> the page example.
>>>
>>> These don’t work:
>>> put value(“getPageNumber (tID)", card "MITA" of stack "MITA") into tResult
>>> put value("getPageNumber" & (tID), card "MITA" of stack "MITA") into
>>> tResult
>>>
>>> What do I do?
>>>
>>> Peter Bogdanoff
>>> _______________________________________________
>>> use-livecode mailing list
>>> [hidden email]
>>> Please visit this url to subscribe, unsubscribe and manage your
>>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Call a function on another card

Rick Harrison via use-livecode
In reply to this post by Rick Harrison via use-livecode
> On Feb 23, 2017, at 12:32 PM, Peter Bogdanoff via use-livecode <[hidden email] <mailto:[hidden email]>> wrote:
>
> put value("myFunction(hello, world)", group "myGroup" of card "myCard") into tResult
>
> I want to use a variable as a parameter instead of “hello, world” as in the page example.

You could try:

put value(“myFunction(“ & myVar & ")", group "myGroup" of card "myCard") into tResult

Paul



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Call a function on another card

Rick Harrison via use-livecode
In reply to this post by Rick Harrison via use-livecode
Bob,

This is a good question. In my case, each card script has script local variables that are used only for that card.

In this unusual case (I’m creating a text search method) I need to access the contents of those variables from another stack.

I indeed would like to move common handlers to a stack or library script, but these handlers use many local variables relevant to the individual cards. I have not yet thought of a simple way to use common handlers without a LOT of passing of local variable data.

Instead of local variables, I suppose I could set custom properties in the library stack for each bit of data. But it seems awkward to me to have in the library script:

put the FieldTextArray of stack “MLib” into tVar # Stored in a custom property
return tVar [“HTML”]
        then in the card script:
set the htmlText of field “Text” to it

        instead of simply (in the card script):
set the htmlText of field “Text” to sFieldTextData [“HTML”]  # Card local variable

And then, custom properties would have to be emptied after each session.

Peter


On Feb 23, 2017, at 2:03 PM, Bob Sneidar via use-livecode <[hidden email]> wrote:

> When I encounter situations like these, I begin to ask myself why the handler is in a card script. If it needs to be accessible from other cards, it should probably be moved to the stack script, or put into a button and inserted into front or back. I have 3 buttons I use for this effect: Utilities, Validations and Database Functions. Utilities and Database functions I insert into back. The validations I insert into front in case I want to intercept things like openField or selectionChanged and do things before passing them on.
>
> Bob S
>
>
>> On Feb 23, 2017, at 13:21 , Peter Bogdanoff via use-livecode <[hidden email]> wrote:
>>
>> Yes, thank you, that works. I used:
>>
>> dispatch function "getPageNumber" to card "MITA" of stack "MITA" with tID
>>
>> What came back was in “the result”
>>
>> “it” contained “handled”
>>
>> pb
>>
>> On Feb 23, 2017, at 12:54 PM, Mike Bonner via use-livecode <[hidden email]> wrote:
>>
>>> Will this work for you?
>>> dispatch function "myFunction" to card "myCard"
>>>
>>> put the result into tResult
>>>
>>> Parameters can also be passed using the "with" extension. Unlike the
>>> "call", "send" and "value" handlers, the parameters are sent directly to
>>> the target handler, rather than being extracted from the string used to
>>> call the handler. This negates the need to surround our parameters in
>>> quotes and also allows us to pass arrays
>>>
>>> On Thu, Feb 23, 2017 at 1:32 PM, Peter Bogdanoff via use-livecode <
>>> [hidden email]> wrote:
>>>
>>>> Hi,
>>>>
>>>> I’m reading on
>>>> http://lessons.livecode.com/m/4071/l/11787-how-to-call-a-
>>>> function-or-command-in-another-object
>>>>
>>>> this:
>>>> put value("myFunction(hello, world)", group "myGroup" of card "myCard")
>>>> into tResult
>>>>
>>>> I want to use a variable as a parameter instead of “hello, world” as in
>>>> the page example.
>>>>
>>>> These don’t work:
>>>> put value(“getPageNumber (tID)", card "MITA" of stack "MITA") into tResult
>>>> put value("getPageNumber" & (tID), card "MITA" of stack "MITA") into
>>>> tResult
>>>>
>>>> What do I do?
>>>>
>>>> Peter Bogdanoff
>>>> _______________________________________________
>>>> use-livecode mailing list
>>>> [hidden email]
>>>> Please visit this url to subscribe, unsubscribe and manage your
>>>> subscription preferences:
>>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>>
>>> _______________________________________________
>>> use-livecode mailing list
>>> [hidden email]
>>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Call a function on another card

Rick Harrison via use-livecode
I may be mistaken, but I think that script locals are accessible to a behavior script. If so, you could keep the script local variables in the card, and the handlers in a library or backscript. I will set up a test for that.

Bob S


> On Feb 23, 2017, at 14:51 , Peter Bogdanoff via use-livecode <[hidden email]> wrote:
>
> Bob,
>
> This is a good question. In my case, each card script has script local variables that are used only for that card.
>
> In this unusual case (I’m creating a text search method) I need to access the contents of those variables from another stack.
>
> I indeed would like to move common handlers to a stack or library script, but these handlers use many local variables relevant to the individual cards. I have not yet thought of a simple way to use common handlers without a LOT of passing of local variable data.


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Call a function on another card

Rick Harrison via use-livecode
I did a quick little test. The card's script local variables are not accessible from the behavior script.

At this point you might consider using card properties instead. This is what I have been doing. This way each card can have it's own "variables" in the form of properties. Then you can have a function in each card script that returns the value stored in the property:

function cardProp pPropName
   return the pPropName of me
end cardProp

Booyah. I use this myself. The nice thing about using properties is that if there is no such property there will not be any error thrown.

Bob S


> On Feb 23, 2017, at 14:56 , Bob Sneidar via use-livecode <[hidden email]> wrote:
>
> I may be mistaken, but I think that script locals are accessible to a behavior script. If so, you could keep the script local variables in the card, and the handlers in a library or backscript. I will set up a test for that.
>
> Bob S
>
>
>> On Feb 23, 2017, at 14:51 , Peter Bogdanoff via use-livecode <[hidden email]> wrote:
>>
>> Bob,
>>
>> This is a good question. In my case, each card script has script local variables that are used only for that card.
>>
>> In this unusual case (I’m creating a text search method) I need to access the contents of those variables from another stack.
>>
>> I indeed would like to move common handlers to a stack or library script, but these handlers use many local variables relevant to the individual cards. I have not yet thought of a simple way to use common handlers without a LOT of passing of local variable data.
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Call a function on another card

Rick Harrison via use-livecode
Thanks Bob, I’ll look at this more closely.

One benefit of using custom properties rather than local variables is that I’ve seen that local variables are sometimes emptied on some script errors when working on a script. Then I have to quit and reload the stack.

Peter


On Feb 23, 2017, at 3:17 PM, Bob Sneidar via use-livecode <[hidden email]> wrote:

> I did a quick little test. The card's script local variables are not accessible from the behavior script.
>
> At this point you might consider using card properties instead. This is what I have been doing. This way each card can have it's own "variables" in the form of properties. Then you can have a function in each card script that returns the value stored in the property:
>
> function cardProp pPropName
>   return the pPropName of me
> end cardProp
>
> Booyah. I use this myself. The nice thing about using properties is that if there is no such property there will not be any error thrown.
>
> Bob S
>
>
>> On Feb 23, 2017, at 14:56 , Bob Sneidar via use-livecode <[hidden email]> wrote:
>>
>> I may be mistaken, but I think that script locals are accessible to a behavior script. If so, you could keep the script local variables in the card, and the handlers in a library or backscript. I will set up a test for that.
>>
>> Bob S
>>
>>
>>> On Feb 23, 2017, at 14:51 , Peter Bogdanoff via use-livecode <[hidden email]> wrote:
>>>
>>> Bob,
>>>
>>> This is a good question. In my case, each card script has script local variables that are used only for that card.
>>>
>>> In this unusual case (I’m creating a text search method) I need to access the contents of those variables from another stack.
>>>
>>> I indeed would like to move common handlers to a stack or library script, but these handlers use many local variables relevant to the individual cards. I have not yet thought of a simple way to use common handlers without a LOT of passing of local variable data.
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Call a function on another card

Rick Harrison via use-livecode
In reply to this post by Rick Harrison via use-livecode
Bob Sneidar wrote:

 > I did a quick little test. The card's script local variables are not
 > accessible from the behavior script.

True, but you may not need to:  each object subscribed to a behavior
script maintains its own set of script-local variables.

--
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  [hidden email]                http://www.FourthWorld.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Call a function on another card

Rick Harrison via use-livecode
Yes, but Peter has a single behavior for all his cards, but unique script local variables for each card. He wants those script local variables to be visible to his behavior.

In a related note, I want to say again that properties can act as scoped variables using the method I described. So properties of a stack or a card or of anything can have the same names, like tableName for instance for each card displaying data from different SQL tables for instance. A behavior script for all the cards can call a function in the actual script of each card and depending on the card you are on will retrieve the properties specific to that card.

A poor man's variable scoping as I have called it before.

Bob S


> On Feb 23, 2017, at 17:42 , Richard Gaskin via use-livecode <[hidden email]> wrote:
>
> Bob Sneidar wrote:
>
> > I did a quick little test. The card's script local variables are not
> > accessible from the behavior script.
>
> True, but you may not need to:  each object subscribed to a behavior script maintains its own set of script-local variables.
>
> --
> Richard Gaskin


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode