[etoys-dev] SQ-903 - Object displayed name does not always match name used to refer to object in scripts
Ricardo Moran
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
> wrote:
> 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]]
ifAbsent: [nil].
foundMorph
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 :)
Cheers,
Richo
>
> Cheers,
>
> -- Scott
>
>
> _______________________________________________
> etoys-dev mailing list
> etoys-dev at squeakland.org
> http://lists.squeakland.org/mailman/listinfo/etoys-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakland.org/pipermail/etoys-dev/attachments/20110328/327e3974/attachment.html>
More information about the etoys-dev
mailing list