What are Clones and Realization in OOP
Clones in Scratch are similar to Classes and Instances in object-oriented programming (OOP).
An Instance is a specific realization of a Class. For example, every human has a name, gender, birthday, and so on. In OOP, Human is a class, and each particular human has a different set of attributes. Take me as an example: my name is Shawn, and my gender is male. These are my attributes. So if you use an object to store my attributes, this object will be an Instance of Class Human.
In Scratch, a sprite can be used as a Class, and its clones can be used as Instances. In OOP, a Class only contains functions and definitions of attributes. For example, the Human class has two functions called eat() and sleep(), and has attributes like name, gender, and so on. When you clone a sprite (realize a class), you will get a clone, of which the attributes can be set.
Why use Dolly?
The most important thing in OOP is to manage classes and their instances. However, in Scratch, it’s very hard to do so. You will like Dolly if you want to …
- Clone any sprites, including the currently selected sprite, without using any hacking techniques
- Sense whether a specific clone is touching a specific sprite
- Clone a sprite and store specific data (for example, ID) to it
- Get any clones whose specific data matches the given data
- Delete any clone of any sprite
- Set or get any property and key-value pairs of a specific clone on the stage
Best Practices
Modules
Dolly has three major parts: Touching, Clone and Delete, and K/V and Property.
Module | Description |
Touching | Extend Scratch Touching features to:
1. sense whether the current sprite is touching a specific sprite or its clones
2. get a specific property of the clone which is touching a specific sprite |
Clone and Delete | 1. create a clone with a specific key-value pair
2. delete a clone with a particular id
3. receive an event if a sprite is cloned or deleted |
Key Value and Property | 1. get any properties if the key value matches
2. access any properties of a clone
3. get/set a value for a given key of a specific object
4. get the current clone’s value for a given key |
Functions and Definitions
Touching
Check whether the current sprite/clone is touching a specific sprite’s clone, or the sprite itself.
Property | Description | Example Value |
Sprite | Select a sprite to check | Sprite 1 |
Mode | - sprite and its clones
- sprite only |
If it is touching a sprite’s clone, get a property of the clone.
Property | Description | Example Value |
Property | The property of the sprite’s clone:
- id: the unique id of this clone/sprite
- x position
- y position
- size: 0-100, the size of this sprite
- visible: true/false
- direction: 0-360
- # of costumes
- costume name | |
Sprite | The original sprite of the clone. |
Clone and Delete
Create, delete, and monitor events when the clone is created or deleted.
Clone a specific sprite and set a key-value pair to the clone.
Property | Description | Example Value |
Sprite | Which sprite do you want to clone? | |
Key | The key to storing the value | id |
Value | The value paired to the key | 1 |
Delete a clone with a specific clone id.
To delete a clone with this block, you must get the clone’s id. If you want to delete a clone of Sprite1 with key = “id” and value = “1”, you should code like this:
When a specific Sprite is cloned, the following event will be triggered:
Property | Description | Example Value |
Sprite | Which sprite is cloned? | |
Key | The key given when cloning this sprite | |
Value | The value given when cloning this sprite |
When a specific Sprite clone is deleted, the following event will be triggered:
Property | Description | Example Value |
Sprite | Which sprite’s clone is deleted | |
Id | The unique id of this clone |
Key, Value, and Property
With this module, you can find a clone, get the property of the clone, or set/get the value of the clone for the given key.
Get a specific property of the chosen sprite’s clone if the key-value pair matches the given one.
Get a specific property by object id (clone id).
If you have the unique id of a clone/object, you can set the value for the key at any time by using this block:
With a clone/object id, you can get the value of a key at any time by using this block:
If the current clone wants to get the value of the key, use this:
If the current clone wants to check if the key-value pair matches the given pair, this will help you:
You can get a property of the current object/clone by using this:
Roadmap and Logs
Version | Log / What’s New |
0.1.2 | Added:
1. my value of key
2. my value of the key is equal to
3. my properties
Shawn at 19 Juli. 2022 |
0.1.1 | Init launch with basic features
Shawn at 9 Juli. 2022 |