Bad "Behaviour"

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Bad "Behaviour"

Post by user#606 » Fri Apr 17, 2009 9:01 pm

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).

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10050
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld » Fri Apr 17, 2009 10:35 pm

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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

822163
Posts: 3
Joined: Thu Feb 26, 2009 4:08 pm

Post by 822163 » Fri Apr 17, 2009 10:54 pm

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?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10050
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld » Sat Apr 18, 2009 12:13 am

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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Post by user#606 » Sat Apr 18, 2009 10:44 am

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?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10050
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld » Sat Apr 18, 2009 4:08 pm

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?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Post by user#606 » Mon Apr 20, 2009 9:04 am

You are right about the numbers being high. It is because I used an actual developing piece of software.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10050
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld » Mon Apr 20, 2009 2:14 pm

What does that mean?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

trevix
Posts: 1079
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Post by trevix » Mon Apr 20, 2009 7:32 pm

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â€

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Post by mwieder » Sat Apr 25, 2009 5:08 pm

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.

Post Reply