how to reference code outside of current card?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
how to reference code outside of current card?
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)
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)
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
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
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.
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.
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:
The ":" after MessageTraps should be an end-quote correct?
Code: Select all
insert script of button "MessageTraps: into front
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.
-
- VIP Livecode Opensource Backer
- Posts: 10049
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Thanks, Bill - good catch. Now fixed.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 10049
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
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.

Now fixed.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
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.
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.
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
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
Code: Select all
insert the script of btn "button1" of card "card1" into back
Thanks
Bill
To be clear, the code in the script is irrelevant. If could just be:
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
on mouseUp
answer "hello"
end mouseUp
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.
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
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
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!Code: Select all
insert the script of btn "button1" of card "card1" into back
Thanks
Bill
Hi Bill,
put 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 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
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
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
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
How is that? The dictionary for "send" says:
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.
Code: Select all
Summary:
Sends a message to an 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
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.
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,
putinto your stack script and try with a simple stack and 2 images and 2 cards,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
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 stackand 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.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
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