Page 1 of 3

how to reference code outside of current card?

Posted: Thu Oct 30, 2008 7:42 am
by billworld
This has got to be possible, but, I'm not finding anything searching the docs for "subscript".

How do I reference a chunk of code (e.g. a script) stored outside of the current card?

Bill (I'll eventually read all of the docs, first need to make sure this RR tool has the functionality I need)

Posted: Thu Oct 30, 2008 8:48 am
by malte
Hi Bill,

what exactly do you want to do? Your question sounds a bit vague to me. Do you want to work with script libraries? Reuse code bits in ore than one place? For starters you might want to look up "insert script" and "start using" in the dictionary. Also you should look at "send" and "call".

Hope that helps.

Malte

Posted: Thu Oct 30, 2008 10:03 am
by SparkOut
also it would be worth understanding about the message path and how a handler reference travels.
There's an article here http://www.fourthworld.com/embassy/arti ... _path.html by Richard Gaskin (our resident FourthWorld here) which should help you understand the various concepts.

Posted: Thu Oct 30, 2008 2:38 pm
by billworld
Thanks guys. Now I need to read up on "insert script". A quick glance at the URL below shows the following code fragment which looks to be in error:

Code: Select all

insert script of button "MessageTraps: into front
The ":" after MessageTraps should be an end-quote correct?
SparkOut wrote:also it would be worth understanding about the message path and how a handler reference travels.
There's an article here http://www.fourthworld.com/embassy/arti ... _path.html by Richard Gaskin (our resident FourthWorld here) which should help you understand the various concepts.

Posted: Thu Oct 30, 2008 4:13 pm
by FourthWorld
Thanks, Bill - good catch. Now fixed.

Posted: Fri Oct 31, 2008 12:45 am
by SparkOut
At the risk of seeming petty (which is certainly not the intention), there's another similar trailing colon instead of quote in the backscripts section too.
insert script of button "ScriptUtilities: into back

Posted: Sat Nov 01, 2008 2:42 am
by FourthWorld
Not petty at all. On the contrary, after all the years this has been online I wish someone would have caught that sooner. Maybe you're the first to have read it. :)

Now fixed.

Posted: Sat Nov 01, 2008 3:37 am
by paul_gr
FourthWorld wrote:Maybe you're the first to have read it. :)
Not at all -- I found all of your articles very well written and informative, and I'm sure many others have as well.

Paul

Posted: Sat Nov 01, 2008 11:27 am
by SparkOut
Absolutely!

Posted: Tue Nov 18, 2008 6:32 pm
by billworld
After reading up on "insert script" I'm still not getting it. For example, I'm not getting how to reference the following script from multiple diff. images/icons located throughout my app.

Code: Select all

on mouseUp
   put name of target into myGroup
   set the itemdelimiter to quote
   put item 2 of myGroup into myGroup

   if visible of grp myGroup is true then
      set visible of grp myGroup to false
      else set visible of grp myGroup to true

    set layer of grp myGroup to top
end mouseUp

on mouseEnter
    set blendlevel of target to 80
end mouseEnter

on mouseLeave
    set blendlevel of target to 0
end mouseLeave
Assuming this script is located in button1 on card1 and I want to reference it from image1 on card2, when I use the following code as the script for image1 nothing happens when I click on image1 in run mode.

Code: Select all

insert the script of btn "button1" of card "card1" into back
Logic (and my understanding of the docs) is telling me this should work, but it's not. I realize I'm missing something fundamental here. Please help!

Thanks

Bill

Posted: Tue Nov 18, 2008 7:23 pm
by billworld
To be clear, the code in the script is irrelevant. If could just be:

Code: Select all

on mouseUp
answer "hello"
end mouseUp
It's the part about referencing that script from somewhere else that's got me stumped. The User Guide mentions that custom commands and functions can be referenced via "insert script". However, the dictionary doesn't specifically mention that ONLY custom commands/functions are allowed. Not sure which one to believe, or if that's even related to the problem.

So, if the script above is contained on "button1" of "card1" I should be able to reference it in "button2" on "card2" simply with the following, correct?

Code: Select all

insert script of "button1" of "card1" into back
billworld wrote:After reading up on "insert script" I'm still not getting it. For example, I'm not getting how to reference the following script from multiple diff. images/icons located throughout my app.

Code: Select all

on mouseUp
   put name of target into myGroup
   set the itemdelimiter to quote
   put item 2 of myGroup into myGroup

   if visible of grp myGroup is true then
      set visible of grp myGroup to false
      else set visible of grp myGroup to true

    set layer of grp myGroup to top
end mouseUp

on mouseEnter
    set blendlevel of target to 80
end mouseEnter

on mouseLeave
    set blendlevel of target to 0
end mouseLeave
Assuming this script is located in button1 on card1 and I want to reference it from image1 on card2, when I use the following code as the script for image1 nothing happens when I click on image1 in run mode.

Code: Select all

insert the script of btn "button1" of card "card1" into back
Logic (and my understanding of the docs) is telling me this should work, but it's not. I realize I'm missing something fundamental here. Please help!

Thanks

Bill

Posted: Tue Nov 18, 2008 7:38 pm
by Mark
Hi Bill,

I think you want to use the send command instead of the insert command.

Best,

Mark

Posted: Tue Nov 18, 2008 8:00 pm
by bn
Hi Bill,

put

Code: Select all

on mouseEnter
    put the long name of the target into tTarget
    if tTarget contains "image" or tTarget contains "group" then
        set blendlevel of tTarget to 80
    end if
end mouseEnter

on mouseLeave
    put the long name of the target into tTarget
    if tTarget contains "image" or tTarget contains "group" then
        set blendlevel of tTarget to 0 
    end if
end mouseLeave
into your stack script and try with a simple stack and 2 images and 2 cards,
No need to make a front / back script, which I find hard to manage anyways. In your script you process plain events when they happen, no need to catch them in a front script. And if you put the script at the stack level, no need for a back script.

for your group script, if you hide your group, as in your script, it will never show up again since it never gets the mouseUp needed.
add this to the stack script to your test stack

Code: Select all

on mouseUp
    put the long name of the target into tTargetName
    if tTargetName contains "button" then
        if visible of tTargetName is true then 
            set visible of tTargetName to false 
        else set visible of tTargetName to true 
    end if
end mouseUp 
and put a button or two on a card. This works once (as long as the button has no mouseUp code or the button passes the mouseUp event). The button once hidden will not get a mouseUp event, since it is hidden. The same of course goes for groups.
if you want to go for the groups then you have to watch, who gets the message, e.g. the mouseUp. Is it the group or an image in the group, you would have to track for that. That is why I look for the long name, then a group would be in the long name, but if you look for the name of the target and the actual target is an image although member of a group you would not find out from the name of the target
If I got you right this should give you some clues.
cheers
bernd

Posted: Wed Nov 19, 2008 1:12 am
by billworld
How is that? The dictionary for "send" says:

Code: Select all

Summary: 
Sends a message to an object. 
I'm not looking to just send a message to an object, I'm simply trying to understand how to insert/reference a whole block of code (containing multiple handlers) into another card/object. I'm used to designing my code in FMP with various subscripts, each which is designed context-insensitive with variables, etc. If I have a complicated routine handling navigation and icon display and said same routine will appear across many stacks and objects isn't there a basic way of referring to one instance of said code routine without having to copy/past the same block of code to each stack/object?

I just want to have a reference to the main code block so the code is manageable.

I'm just not getting how to do that with RR.

Mark wrote:Hi Bill,

I think you want to use the send command instead of the insert command.

Best,

Mark

Posted: Wed Nov 19, 2008 1:28 am
by billworld
Thanks, but, this isn't completely helping. I see how bringing the script to the stack level can help in some ways, but, the block of code I need to reference needs to work across multiple sub-stacks. Can't I just insert a pointer somewhere to the main block of code?

Regardless, the second block you have here is showing/hiding the target (e.g. what is clicked on) vs what I had which is controlling a specific group which just so happens to have the same name as the image which is clicked on (but is not part of the group).

Anyway, I'm still not getting how to deal with referencing blocks of code in RR.

Are there any helpful tutorial stacks on this? I haven't found any readily after a cursory look. Maybe if I just had my hands on a stack which demonstrated the concept of how a single block of code in object A on card 1 in stack "myStack" could be re-used across multiple stacks and objects all in the same app (e.g. via pointer reference) then this would make sense to me.
bn wrote:Hi Bill,

put

Code: Select all

on mouseEnter
    put the long name of the target into tTarget
    if tTarget contains "image" or tTarget contains "group" then
        set blendlevel of tTarget to 80
    end if
end mouseEnter

on mouseLeave
    put the long name of the target into tTarget
    if tTarget contains "image" or tTarget contains "group" then
        set blendlevel of tTarget to 0 
    end if
end mouseLeave
into your stack script and try with a simple stack and 2 images and 2 cards,
No need to make a front / back script, which I find hard to manage anyways. In your script you process plain events when they happen, no need to catch them in a front script. And if you put the script at the stack level, no need for a back script.

for your group script, if you hide your group, as in your script, it will never show up again since it never gets the mouseUp needed.
add this to the stack script to your test stack

Code: Select all

on mouseUp
    put the long name of the target into tTargetName
    if tTargetName contains "button" then
        if visible of tTargetName is true then 
            set visible of tTargetName to false 
        else set visible of tTargetName to true 
    end if
end mouseUp 
and put a button or two on a card. This works once (as long as the button has no mouseUp code or the button passes the mouseUp event). The button once hidden will not get a mouseUp event, since it is hidden. The same of course goes for groups.
if you want to go for the groups then you have to watch, who gets the message, e.g. the mouseUp. Is it the group or an image in the group, you would have to track for that. That is why I look for the long name, then a group would be in the long name, but if you look for the name of the target and the actual target is an image although member of a group you would not find out from the name of the target
If I got you right this should give you some clues.
cheers
bernd