Oddity in 'currentCard' function?

Mark Waddingham mark at livecode.com
Wed Oct 25 00:34:53 EDT 2023


On 2023-10-24 18:00, Paul Dupuis via use-livecode wrote:
> I think I found a oddity in the "currentCard" property.
> 
> The documentation states that the currentCard property return the short 
> name of the current card of a stack:
> 
> for example: put the currentCard of stack "Untitled 1" into tCardName
> 
> You can then execute code such as: set the myProperty of cd tCardName 
> of stack "Untitled 1" to tValue

...

> But again, breaking that example above (set the myProperty of the 
> currentCard of stack "Untitled 1" to tValue) into 2 lines:
> put the currentCard of stack "Untitled 1" into tCardName
> set the myProperty of cd tCardName of stack "Untitled 1" to tValue
> FAILS if the card has no name.
> 
> Something just seems off here?

As Jacque said, if an object has an empty name then the short name 
returns `<chunk> id <id>` (i.e. an id chunk) - this is long standing 
behavior and one which I'm not sure is entirely helpful (it should 
perhaps just return empty!).

You see the same effect in other properties which return a 'short name' 
- e.g. the menubar of a stack. So its entirely consistent with 'object 
name' properties. (In these cases there is no string which such 
properties could return which would help distinguish unnamed things and 
that could be used to resolve them in some sort of chunk in a consistent 
manner as object names can be arbitrary strings).

If you want to do stuff with the current card of a stack, then don't use 
the currentCard property - 'this card of stack ...' *is* a chunk 
reference and thus it doesn't care whether the card has a name or not.

If you want the long id of the current card of a stack to manipulate 
'out of context' then use the long id:

    put the long id of this card of stack ... into tCardId

Of course, if you really want to use the currentCard (for whatever 
reason), then you need to make sure all your cards have names (which to 
be fair, is a good habit to get into - as is naming all objects with 
some, unique, name!).

Warmest Regards,

Mark.

-- 
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Build Amazing Things



More information about the use-livecode mailing list