Bad "Behaviour"
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Bad "Behaviour"
A good idea, but I cannot get the hang of it. Yes, I read the 2 part tutorial, but there was so much stuff that was nothing to do with Behaviour, I couldnt follow it. I tried the Behaviour Notes in the program folder, but it was too deep for me at this stage.
Can we try something simple like two cards in a stack. One called Card "Introduction" id 1002 the other called Card "ADL1B" id 1009
The first card has a button called Button "Button1" id 6542 and contains the script:-
on mouseUp
beep
end mouseUp
The second card has a button called Button "Button2" id 6544 and the script there is supposed to "activate or run" the script in Button1
The script I tried was:-
on mouseUp
set the parentScript of Button id 6542 to the long id of button id 6544
end mouseUp
Of course it didnt work!
What should I have used?
I prefer to work with id numbers rather than names because there is no ambiguity (for me).
Can we try something simple like two cards in a stack. One called Card "Introduction" id 1002 the other called Card "ADL1B" id 1009
The first card has a button called Button "Button1" id 6542 and contains the script:-
on mouseUp
beep
end mouseUp
The second card has a button called Button "Button2" id 6544 and the script there is supposed to "activate or run" the script in Button1
The script I tried was:-
on mouseUp
set the parentScript of Button id 6542 to the long id of button id 6544
end mouseUp
Of course it didnt work!
What should I have used?
I prefer to work with id numbers rather than names because there is no ambiguity (for me).
-
- VIP Livecode Opensource Backer
- Posts: 10050
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
I think the only problem is that the assignment of the behavior uses an incomplete reference: you indicate which button, but no on which card.
Try this:
on mouseUp
set the parentScript of Button id 6542 to the long id of button id 6544 of cd "Introduction"
end mouseUp
Try this:
on mouseUp
set the parentScript of Button id 6542 to the long id of button id 6544 of cd "Introduction"
end mouseUp
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
Thank you for that, I will try that tomorrow.
I am also wondering if I have misunderstood the purpose of Behaviours.
Do you remember the term "subroutine" from BASIC? what I want to achieve is to write a piece of code that lives in one place and is called by a simple phrase.
I tried with a Custom Handler and it worked perfectly in the simple experiment I set up, but refused to work in the proper program. It reported "Cant find Handler". In fact, a custom handler written by someone else that worked only on in the script it was created in, refused to work in the program elsewhere. It reported "Cant find Handler".
I thought I could make use of Behaviours to do the same thing.
Which is the best for the reuse of code?
I am also wondering if I have misunderstood the purpose of Behaviours.
Do you remember the term "subroutine" from BASIC? what I want to achieve is to write a piece of code that lives in one place and is called by a simple phrase.
I tried with a Custom Handler and it worked perfectly in the simple experiment I set up, but refused to work in the proper program. It reported "Cant find Handler". In fact, a custom handler written by someone else that worked only on in the script it was created in, refused to work in the program elsewhere. It reported "Cant find Handler".
I thought I could make use of Behaviours to do the same thing.
Which is the best for the reuse of code?
-
- VIP Livecode Opensource Backer
- Posts: 10050
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
This may be helpful:
Extending the Runtime Revolution Message Path
An introduction to using Libraries, FrontScripts, BackScripts and Behaviors
in Runtime Revolution's Transcript Programming Language
http://www.fourthworld.com/embassy/arti ... _path.html
Extending the Runtime Revolution Message Path
An introduction to using Libraries, FrontScripts, BackScripts and Behaviors
in Runtime Revolution's Transcript Programming Language
http://www.fourthworld.com/embassy/arti ... _path.html
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: 10050
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Is 6544 the actual object ID?
That's a pretty high number. The engine starts numbering with the first card at ID 1001, and everything in a stack is incremented from there. Have you actually put more than 5,000 objects in that stack?
That's a pretty high number. The engine starts numbering with the first card at ID 1001, and everything in a stack is incremented from there. Have you actually put more than 5,000 objects in that stack?
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: 10050
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
What does that mean?
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
I think he was saying that there are many more objects in his stack.
Anyway, I cannot make Behaviors work either.
Image control:
Anyway, I cannot make Behaviors work either.
Image control:
Code: Select all
on MouseUp
set the parentScript of me to the long id of button ID 148734 of card “XXâ€
The keyword "parentScript" has been deprecated. It will still work for now, but it's better to use the word "behavior". You can set the behavior of a control from a script by executing a line of the form
set the behavior of control x to the long id of button y
or in the property inspector (type "button id NNNN" in the behavior box)
Your example won't work because you're overriding the mouseUp handler in your image control. If you really want to put the mouseUp handler in the behavior object then get rid of the mouseUp handler in the image control. Set the behavior of the image control to the long id of the behavior button, then click the mouse in the image. That should trigger the mouseUp handler in the behavior button.
set the behavior of control x to the long id of button y
or in the property inspector (type "button id NNNN" in the behavior box)
Your example won't work because you're overriding the mouseUp handler in your image control. If you really want to put the mouseUp handler in the behavior object then get rid of the mouseUp handler in the image control. Set the behavior of the image control to the long id of the behavior button, then click the mouse in the image. That should trigger the mouseUp handler in the behavior button.