pytchlang / pytch-vm

Pytch: Core language and runtime
Other
3 stars 7 forks source link

Feature: Discovery of sprite instances #17

Closed bennorth closed 4 years ago

bennorth commented 4 years ago

Scratch supports reporter blocks like (x-position of Cat). Add a facility to retrieve the live instance/s of a particular Sprite class, in three ways: the original; all clones; all instances. Used as in

the_original_alien = pytch.the_original(Alien)

or

all_alien_clones = pytch.all_clones_of(Alien)
# List of clones; does not include original; can be empty.

or

all_aliens_including_original = pytch.all_instances_of(Alien)
# List of all instances; original will be at [0] followed
# by clones; will never be empty.
#
# Is 'instances' the most user-friendly word to use here?

Comments welcome on whether this is the right API. We could alternatively do

the_original_alien = Alien.the_original()

but I think I prefer the approach in this PR, because the list of live (=registered) instances is a property of the live Pytch context rather than of the class itself.

bennorth commented 4 years ago

Closing in favour of #18.