There may come a time when a user may need to assign an arbitrary number of sprites a unique identifier. For instance, say the user has ten bullet sprites with a local variable. Rather than individually assigning each of them a number in a set () to () block, it might be handy to do this automatically. That way, a script could specifically call bullet number seven without hard-coding it. First, create a global (spriteCount) variable. Then, on the stage add this code: When flag clicked: set spriteCount to 0 broadcast [count sprites] and wait //do something afterwards
| Attributes | Values |
|---|
| rdfs:label
| |
| rdfs:comment
| - There may come a time when a user may need to assign an arbitrary number of sprites a unique identifier. For instance, say the user has ten bullet sprites with a local variable. Rather than individually assigning each of them a number in a set () to () block, it might be handy to do this automatically. That way, a script could specifically call bullet number seven without hard-coding it. First, create a global (spriteCount) variable. Then, on the stage add this code: When flag clicked: set spriteCount to 0 broadcast [count sprites] and wait //do something afterwards
|
| dcterms:subject
| |
| abstract
| - There may come a time when a user may need to assign an arbitrary number of sprites a unique identifier. For instance, say the user has ten bullet sprites with a local variable. Rather than individually assigning each of them a number in a set () to () block, it might be handy to do this automatically. That way, a script could specifically call bullet number seven without hard-coding it. First, create a global (spriteCount) variable. Then, on the stage add this code: When flag clicked: set spriteCount to 0 broadcast [count sprites] and wait //do something afterwards Now, for all the sprites you want to count (and generally these will be clones of the same sprite) add this script: When I receive [count sprites]: change spriteCount by 1 set myNumber to spriteCount //Swap these to start the count at 0 instead of 1 Then, when the flag is clicked, each sprite will get a unique number in (myNumber).
|