[etoys-dev] SQ-903 - Object displayed name does not always match name used to refer to object in scripts
richi.moran at gmail.com
Mon Mar 28 08:43:43 EDT 2011
On Sat, Mar 26, 2011 at 5:34 PM, Scott Wallace <scott.wallace at squeakland.org
> 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...> ]
That's much better. IMHO, for what Steve is trying to do, it might be good
to add this snippet to the Player class, maybe in the form of:
withExternalName: aString do: aBlock
| foundMorph |
foundMorph := World findDeepSubmorphThat: [:each | each externalName =
aString and: [each player notNil]]
ifNotNil: [aBlock value: foundMorph player]
So that he could write, from a script:
Player withExternalName: 'Cat' do: [:cat | cat forward: 5].
And this way we can hide the ugly code away...
Of course, I'm not in favor of polluting the Player class but if Steve finds
it useful I guess one more method wouldn't hurt :)
> -- Scott
> etoys-dev mailing list
> etoys-dev at squeakland.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the etoys-dev