Page 1 of 1

Assigning behaviors to cards

Posted: Thu Jul 05, 2012 4:31 pm
by rbrucep
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

Re: Assigning behaviors to cards

Posted: Thu Jul 05, 2012 4:40 pm
by Klaus
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

Re: Assigning behaviors to cards

Posted: Thu Jul 05, 2012 6:05 pm
by rbrucep
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

Re: Assigning behaviors to cards

Posted: Thu Jul 05, 2012 6:14 pm
by mwieder
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

Re: Assigning behaviors to cards

Posted: Thu Jul 05, 2012 6:15 pm
by mwieder
Update: I finally read Klaus' reply and see that he already mentioned the long id thing. :oops:

Your genius/my idiocy...

Posted: Thu Jul 05, 2012 7:08 pm
by rbrucep
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

Re: Assigning behaviors to cards

Posted: Sun May 04, 2014 7:41 pm
by Simon Knight
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

Re: Assigning behaviors to cards

Posted: Mon May 05, 2014 7:52 am
by Simon Knight
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