Page 1 of 1
Bad "Behaviour"
Posted: Fri Apr 17, 2009 9:01 pm
by user#606
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).
Posted: Fri Apr 17, 2009 10:35 pm
by FourthWorld
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
Posted: Fri Apr 17, 2009 10:54 pm
by 822163
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?
Posted: Sat Apr 18, 2009 12:13 am
by FourthWorld
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
Posted: Sat Apr 18, 2009 10:44 am
by user#606
I tried the code you suggested, but get the error
executing at 10:40:56 AM
Type Chunk: no such object
Object Button2
Line set the parentScript of Button id 6542 to the long id of button id 6544 of cd "Introduction"
Hint 6544
What hav I missed I wonder?
Posted: Sat Apr 18, 2009 4:08 pm
by FourthWorld
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?
Posted: Mon Apr 20, 2009 9:04 am
by user#606
You are right about the numbers being high. It is because I used an actual developing piece of software.
Posted: Mon Apr 20, 2009 2:14 pm
by FourthWorld
What does that mean?
Posted: Mon Apr 20, 2009 7:32 pm
by trevix
I think he was saying that there are many more objects in his stack.
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â€
Posted: Sat Apr 25, 2009 5:08 pm
by mwieder
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.