I've been working with LiveCode for a few months now and there is one major thing I can't figure out, how do you share/use subroutines across objects and across cards?
I have 3 buttons on a card, and I would like the data on all the fields on the card to be saved at the end of each "object" completion. If I add the code to each button it works, but duplicated code, harder to edit.
If I setup all a global variables that seems to help, but with the same results, I have to code the variables on each object/button.
What am I missing?
And is there a list of the ON reserve commands? On CardOpen, on ScriptOpen, etc!? Haven't found list like this in the manuals or online help...
Thanks.
~David
Should have figured this out by now!!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Should have figured this out by now!!
Hi David,
(Cheap) Example: Instead of scripting your button(s) like this
Put this into the card script:
Then you can have a lot of buttons that do almost the same but with this script:
Or have another button do the same but with another parameter:
If you ever need to modify the script, just do it and the buttons will follow
You get the picture...
Open the dictionary (menu: Help) and click "Language -> Message", all these mesages that will appear are the reserved message names "ON".
Best
Klaus
Do not put the logic (means the atcual handler) into the buttons scripts, but in the card or stack script!revRider wrote:I've been working with LiveCode for a few months now and there is one major thing I can't figure out, how do you share/use subroutines across objects and across cards?
I have 3 buttons on a card, and I would like the data on all the fields on the card to be saved at the end of each "object" completion. If I add the code to each button it works, but duplicated code, harder to edit.
If I setup all a global variables that seems to help, but with the same results, I have to code the variables on each object/button.
What am I missing?
(Cheap) Example: Instead of scripting your button(s) like this
Code: Select all
on mouseup
beep 3
answer "I beeped 3 times"
end mouseup
Code: Select all
command do_the_beep_and_answer_it howOften
beep howOften
answer "I beeped" && howOften && "times"
end do_the_beep_and_anser_it
Code: Select all
on mouseup
do_the_beep_and_answer_it 2
end mouseup
Code: Select all
on mouseup
do_the_beep_and_answer_it 14
end mouseup

You get the picture...
Thats "opencard" actually!revRider wrote:And is there a list of the ON reserve commands? On CardOpen, on ScriptOpen, etc!? Haven't found list like this in the manuals or online help...

Open the dictionary (menu: Help) and click "Language -> Message", all these mesages that will appear are the reserved message names "ON".
Best
Klaus
Re: Should have figured this out by now!!
Hi.
This is a basic concept that you absolutely MUST learn. The good news is that it is easy, and easy to experiment with.
Make a stack with three buttons. Name them as you wish. In the card (or stack) script, write:
on mouseUp
answer the name of the target
end mouseUp
Press any button. You will get the name of that button. Read up on "the Target". Try to embellish this simple script.
But this is only one small experiment into learning how messages pass up a hierarchy of objects in a natural, predictable way. Read the user manual. Write back when you get stuck again (you will). But by that time you will be well on your way...
Craig Newman
This is a basic concept that you absolutely MUST learn. The good news is that it is easy, and easy to experiment with.
Make a stack with three buttons. Name them as you wish. In the card (or stack) script, write:
on mouseUp
answer the name of the target
end mouseUp
Press any button. You will get the name of that button. Read up on "the Target". Try to embellish this simple script.
But this is only one small experiment into learning how messages pass up a hierarchy of objects in a natural, predictable way. Read the user manual. Write back when you get stuck again (you will). But by that time you will be well on your way...
Craig Newman