[etoys-dev] SQ-903 - Object displayed name does not always match name used to refer to object in scripts
Scott Wallace
scott.wallace at squeakland.org
Sat Mar 26 16:34:04 EDT 2011
On Mar 26, 2011, at 11:01 AM, Ricardo Moran wrote:
>
> foundPlayer := ActiveWorld presenter reallyAllExtantPlayersNoSort
> detect: [:p |(p costume externalName = 'Cat') and: [p costume isInWorld]]
> ifNone: [nil].
> foundPlayer ifNotNil:
> [ <proceed to do something to or with foundPlayer...> ]
>
> Wouldn't that be equivalent to my script?
>
> (World findDeepSubmorphThat: [:each | each player externalName = aString] ifAbsent: []) player
Hi, Ricardo,
Yes, you're right. Sorry that I'd lost sight of the earlier history of this thread...
However, the "player" of most morphs is nil, so "each player externalName" will often generate an error. Instead, since it's really the morph and not the player that bears the "externalName" anyway, a bulletproofed improvement might be:
foundMorph := World findDeepSubmorphThat: [:each | (each externalName = aString) and: [each player notNil]] ifAbsent: [nil].
foundMorph ifNotNil:
[foundPlayer := foundMorph player.
< proceed to do something to or with foundPlayer...> ]
Cheers,
-- Scott
More information about the etoys-dev
mailing list