Assigning behaviors to cards

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
rbrucep
Posts: 21
Joined: Thu Jul 05, 2012 4:25 pm

Assigning behaviors to cards

Post by rbrucep » Thu Jul 05, 2012 4:31 pm

I'm writing a quiz-generating program and for each question, a new card is created of one of just a few types.
I'd like to assign cards a behavior from a stock collection rather than cloning cards with the same behavior (especially since this will let me update code efficiently)

However, when I use

set the behavior of this card to btn "clickTuteCard_script" of card "Behaviors" of stack "ext_Behaviors"

nothing seems to happen. This syntax & location works for assigning behaviors to fields.

I notice that when inspecting objects, there is a field showing what behavior is set for that object.
I can't find such a field for cards
The dictionary includes 'card' as an assignable target for behaviors.

Can anybody see what I'm doing incorrectly or tell me where to look for a card's assigned behavior?

Thanks!
Bruce

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Assigning behaviors to cards

Post by Klaus » Thu Jul 05, 2012 4:40 pm

Hi Bruce,

1. welcome to the forum! :D

2. this line from the dictionary might help you out:
...
set the behavior of XXX to the long id of button "Widget" of card "Behaviors"
## "boldification" by me :-)
...


Best

Klaus

rbrucep
Posts: 21
Joined: Thu Jul 05, 2012 4:25 pm

Re: Assigning behaviors to cards

Post by rbrucep » Thu Jul 05, 2012 6:05 pm

Klaus:
Thanks for the welcome & the suggestion!
Unfortunately, I get the same result--no error, but no evidence that the behavior has been attached. The right-click menu for the card doesn't still has "run card script" dimmed out also.

As I said, what is most worrisome is that I can't find evidence that there is a way to INSPECT an assigned behavior for cards; it's right there in the 'Object inspector' under 'Basic Properties' for other objects, but no such indication in the Card Inspector.

Does anybody have any reason to believe it's not just an overstatement in the docs?

Cheers
Bruce

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

Re: Assigning behaviors to cards

Post by mwieder » Thu Jul 05, 2012 6:14 pm

No, unfortunately the property inspector hasn't kept up with the times. The way to set and view behaviors is with the message box. And you need to use the long id of an object when setting the behavior.

Code: Select all

set the behavior of this card to THE LONG ID OF btn "clickTuteCard_script" of card "Behaviors" of stack "ext_Behaviors"
put the behavior of this card

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

Re: Assigning behaviors to cards

Post by mwieder » Thu Jul 05, 2012 6:15 pm

Update: I finally read Klaus' reply and see that he already mentioned the long id thing. :oops:

rbrucep
Posts: 21
Joined: Thu Jul 05, 2012 4:25 pm

Your genius/my idiocy...

Post by rbrucep » Thu Jul 05, 2012 7:08 pm

Ah, but the "put the behavior" check was useful.

It showed that the behavior was indeed getting attached.
This lead to the discovery that the button's behavior was blank :shock:

Thanks to you both--I'm hummin' along again!
Bruce

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Assigning behaviors to cards

Post by Simon Knight » Sun May 04, 2014 7:41 pm

Hi,
I am attempting to assign a button that resides on a sub stack as a behavior to a card on the main stack. I have tried all the permutations I can think of but still I am unable to get the behavior to assign. I have tried the code below and using the message box as well as numeric ids all to no avail . Any suggestions?

Code: Select all

put "ListOfFieldsCard_Behavior" into tButton
   put "Object Behaviors" into tStack
   
   set the behavior of this stack to the long id of btn tButton of card id 1002 of stack tstack
best wishes
Skids

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Assigning behaviors to cards

Post by Simon Knight » Mon May 05, 2014 7:52 am

Hmmm,

Given the power and importance of behaviors the ide still treats them as a bit of a bodge : some inspector panes show the behavior others do not. I totally failed to assign the behavior stored on a sub stack to a card on the main stack as described above.

This was annoying but nothing to what happened next: the behavior included an on opencard script and somehow it became assigned to a number of the other cards in my stack (but not the one I intended). The opencard call in the behavior made no sense with these cards and multiple errors were posted. Trying to remove the behavior using the message box was not effective so I had to delete the behavior button. Even this was difficult as it refused to delete; I think because there were probably pending calls in error but who knows, in the end I killed it.

Several projects saves and restarts later I went to copy another button and on the paste the first long deleted behavior button reappeared. All very odd, probably a bug but not one I have the strength to write up. In the end I reverted to placing my behavior button on a card in the same stack and the assignment worked.

<Rant>
I think that the inspector of every object that may have a behavior assigned should have a behavior pane that clearly shows the name and location of the behavior button i.e its long id rather than the truncated version that is sometimes displayed at present. Also the pane should allow the navigation through the loaded stacks to the behavior button and allow the behavior to be dropped or disabled. <rant\>

There I feel better now!

Thanks for reading.

best wishes

Simon K
best wishes
Skids

Post Reply