Problem Calling Custom Card Props with the Same Name Using Switch
Jim Bufalini
jim at visitrieve.com
Mon Nov 30 13:27:07 EST 2009
Hi Gregory,
> -----Original Message-----
> From: use-revolution-bounces at lists.runrev.com [mailto:use-revolution-
> Hello Jacques, Jacqueline, Craig, and Jim,
>
> Sadly, it is a bug then. The consequences, as I said, are potentially
> serious for any stack that uses custom props with the same name to
> monitor various states of objects. Jacqueline and Jacques (kind of
> musical, eh?), I experimented a little more and find that it is not
> limited to using y as the variable name or one-letter variable names in
> general. I get the same problem when x is used for the custom prop on
> two different cards and when a two-letter name, xV, is used. The
> problem is also there if you use an If control structure rather than
> Switch, and it is not limited to cards. I set props for two buttons in
> the same way and lost the value of the same-named prop for the second
> button. I haven't used Behaviours yet, but you can readily see how the
> problem could be pervasive there.
>
> Jim, I appreciate the fix you suggest, but when you say long name, do
> you mean the long name of the card? If so, then that does not work
> either. In any case, a bug report is in order.
I gave a very quick answer to you because I do this all the time and, in
fact, ListMagic has identically named custom property sets in the stack(s)
and in each card that you install ListMagic widgets in. If what you say were
true, ListMagic would not work at all.
So I created a stack, added two cards called FirstCard and SecondCard (I
don't like spaces in names) and in cd id 1002 I created a button with the
following script:
ON mouseUp pMouseBtnNo
set the x of cd "FirstCard" of this stack to "123"
set the y of cd "FirstCard" of this stack to "456"
set the y of cd "SecondCard" of this stack to "ABC"
set the z of cd "SecondCard" of this stack to "DEF"
END mouseUp
I then put a button and a field called "fldResult" on FirstCard and
SecondCard. The button has this script:
ON mouseUp pMouseBtnNo
local tX, tY, tZ
----- #
put the short name of this card & cr & the long name of this cd into fld
"fldResult"
SWITCH the short name of this card
CASE "FirstCard"
put the x of (cd the short name of this card) into tX
put the y of (cd the short name of this card) into tY
put return & "x" && tX && "y" && tY after fld "fldResult"
break #
CASE "SecondCard"
put the y of (cd the short name of this card) into tY
put the z of (cd the short name of this card) into tZ
put return & "y" && tY && "z" && tZ after fld "fldResult"
break
DEFAULT
put cr & "Error: It's neither card" into fld "fldResult"
END switch
END mouseUp
On FirstCard I get:
FirstCard
card "FirstCard" of stack "D:/MyStacks/TestCProps.rev"
FirstCard
x 123 y 456
And on SecondCard I get:
SecondCard
card "SecondCard" of stack "D:/MyStacks/TestCProps.rev"
y ABC z DEF
Seems correct to me. ;-)
There is no problem except readability and maintainability of code in using
1 char custom properties and vars. When you experience weirdness like you
are seeing, first put to a field in your stack rather than the msg box to
eliminate any possibility of the msg box contributing to your issue and then
change excessive use of *this* stack or *this* card to something more
specific. Also use parenthesis to resolve a name like a card name first.
Aloha from Hawaii,
Jim Bufalini
More information about the use-livecode
mailing list