Re: SQ-903 - Object displayed name does not always match name used to refer to object in scripts

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: SQ-903 - Object displayed name does not always match name used to refer to object in scripts

Steve Thomas
Scott,

Thanks, using this works fine (mostly), 

On Wed, Mar 2, 2011 at 5:28 AM, Scott Wallace <[hidden email]> wrote:
       catPlayer := ActiveWorld presenter reallyAllExtantPlayersNoSort detect:
               [:p | p costume externalName = 'Cat'] ifNone: [nil].
       catPlayer ifNotNil: [  catPlayer forward: 5  ]

Except when I have multiple Players with the same name in the project. For example if I have a Player with the ExternalName 'Cat' on page 1 and another Player with the ExternalName 'Cat' on page 2.  Then execute the script on Page 2 the 'Cat' on Page 1 moves forward. (Note: in playing around with this at one point the 'Cat' on page 2 did move, but when I renamed the 'Cat' and made a new one it went back to the behavior where the 'Cat' on page 1 moved again.

I changed the script to refer to 'Page' instead of 'ActiveWorld' and that seemed to solve the problem, until I duplicated the page (which causes 'Cat' to become 'Cat1') and then renamed 'Cat1' to 'Cat' then the 'Cat' on the previous page moved.

So is there anyway to specify the 'search order' for players where it looks in its current ?World/Playfield? first?
Of course the simplest answer may be for me to avoid the problem and not use books ;) 

Stephen

_______________________________________________
etoys-dev mailing list
[hidden email]
http://lists.squeakland.org/mailman/listinfo/etoys-dev
Reply | Threaded
Open this post in threaded view
|

Re: SQ-903 - Object displayed name does not always match name used to refer to object in scripts

Scott Wallace
On Mar 25, 2011, at 12:34 AM, Steve Thomas wrote:

> Scott,
>
> Thanks, using this works fine (mostly),
>
> On Wed, Mar 2, 2011 at 5:28 AM, Scott Wallace <[hidden email]> wrote:
>       catPlayer := ActiveWorld presenter reallyAllExtantPlayersNoSort detect:
>               [:p | p costume externalName = 'Cat'] ifNone: [nil].
>       catPlayer ifNotNil: [  catPlayer forward: 5  ]
>
> Except when I have multiple Players with the same name in the project. For example if I have a Player with the ExternalName 'Cat' on page 1 and another Player with the ExternalName 'Cat' on page 2.  Then execute the script on Page 2 the 'Cat' on Page 1 moves forward. (Note: in playing around with this at one point the 'Cat' on page 2 did move, but when I renamed the 'Cat' and made a new one it went back to the behavior where the 'Cat' on page 1 moved again.
>
> I changed the script to refer to 'Page' instead of 'ActiveWorld' and that seemed to solve the problem, until I duplicated the page (which causes 'Cat' to become 'Cat1') and then renamed 'Cat1' to 'Cat' then the 'Cat' on the previous page moved.
>
> So is there anyway to specify the 'search order' for players where it looks in its current ?World/Playfield? first?
> Of course the simplest answer may be for me to avoid the problem and not use books ;)
>
> Stephen

Hi, Stephen,

Yes, the technique we've spoken of will find *some* player of a given name -- not necessarily the one you're hoping for.  The "reallyAllExtantPlayersNoSort" method makes an extreme effort (as its extreme name suggests) to include players that may not currently be "in the world," so name collisions of the sort you mention will arise when "books" involving multiple pages holding players of the same name are used.

If you expect that one and only one player of a given name is actually going to be "in the world" at the moment a particular script is running, and you only want something in the script to happen if such a player *is* found, the following approach should work:

        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...>  ]


Cheers,

 -- Scott
_______________________________________________
etoys-dev mailing list
[hidden email]
http://lists.squeakland.org/mailman/listinfo/etoys-dev
Reply | Threaded
Open this post in threaded view
|

Re: SQ-903 - Object displayed name does not always match name used to refer to object in scripts

Scott Wallace
On Mar 26, 2011, at 3:10 AM, Scott Wallace 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...>  ]


Oops, left an extra right-paren in there by mistake.  The correct code would be:

        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...>  ]
_______________________________________________
etoys-dev mailing list
[hidden email]
http://lists.squeakland.org/mailman/listinfo/etoys-dev
Reply | Threaded
Open this post in threaded view
|

Re: SQ-903 - Object displayed name does not always match name used to refer to object in scripts

Ricardo Moran

On Sat, Mar 26, 2011 at 7:16 AM, Scott Wallace <[hidden email]> wrote:
On Mar 26, 2011, at 3:10 AM, Scott Wallace 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...>  ]


Oops, left an extra right-paren in there by mistake.  The correct code would be:

       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

Cheers,
Richo
 
_______________________________________________
etoys-dev mailing list
[hidden email]
http://lists.squeakland.org/mailman/listinfo/etoys-dev


_______________________________________________
etoys-dev mailing list
[hidden email]
http://lists.squeakland.org/mailman/listinfo/etoys-dev
Reply | Threaded
Open this post in threaded view
|

Re: SQ-903 - Object displayed name does not always match name used to refer to object in scripts

Scott Wallace
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


_______________________________________________
etoys-dev mailing list
[hidden email]
http://lists.squeakland.org/mailman/listinfo/etoys-dev
Reply | Threaded
Open this post in threaded view
|

Re: SQ-903 - Object displayed name does not always match name used to refer to object in scripts

Ricardo Moran


On Sat, Mar 26, 2011 at 5:34 PM, Scott Wallace <[hidden email]> 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
[hidden email]
http://lists.squeakland.org/mailman/listinfo/etoys-dev


_______________________________________________
etoys-dev mailing list
[hidden email]
http://lists.squeakland.org/mailman/listinfo/etoys-dev