Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Sprite Variables
- craftman12
-
Scratcher
51 posts
Sprite Variables
Hi! I am making a new clicker game and I got tired of the normal scratch variables. I want the type of variable where you choose a sprite and it clones and counts your score. I Also DO NOT Want Too Many Sprites. Can Someone Help Me?
- awesome-llama
-
Scratcher
1000+ posts
Sprite Variables
So you want to display numbers using clones?
You can create a single sprite with costumes for every digit or character you want to display. For numbers, you would want at least the digits 0-9. You could also include other symbols such as:
… which can also appear in numbers. Also create a completely blank costume and give it no name at all. (This is used if a number is shorter than the total amount of clones used)
Make sure to also name the costumes to match the character they each will display.
Now, for displaying, you can create clones which each act as one digit of the number. The first clone will display the first digit, the second will display the next, and so on. You get to choose how many clones you want. More clones would mean more digits able to be displayed.
To get each clone acting differently and display the correct digit, you can make use of a local variable. (when creating a variable, set it to “for this sprite only”). This local variable will act as the unique ID for each clone as you can store data unique to the clone it is in rather than have a variable being the same for all as normal (“global”) ones do.
Here's a basic script that can display cloned numbers to help explain it:
Edit: the above comments got cut off. They say:
“each clone will copy the value stored in the original sprite, clone 1 gets digit 1, clone 2 gets digit 2, …”
“the number variable is the variable you want to display with the clones”
Also, another thing to add: this same thing works with displaying text! You just have to add costumes for all the letters.
You can create a single sprite with costumes for every digit or character you want to display. For numbers, you would want at least the digits 0-9. You could also include other symbols such as:
-
+
.
e
Make sure to also name the costumes to match the character they each will display.
Now, for displaying, you can create clones which each act as one digit of the number. The first clone will display the first digit, the second will display the next, and so on. You get to choose how many clones you want. More clones would mean more digits able to be displayed.
To get each clone acting differently and display the correct digit, you can make use of a local variable. (when creating a variable, set it to “for this sprite only”). This local variable will act as the unique ID for each clone as you can store data unique to the clone it is in rather than have a variable being the same for all as normal (“global”) ones do.
Here's a basic script that can display cloned numbers to help explain it:
when green flag clicked // create clones
go to x: (-100) y: (0) // location of the first digit
show
set [digit v] to [1] // the local variable which will control which digit the clone will display
repeat (5) // how many digits you want to display
create clone of [myself v]
change [digit v] by (1) // each clone will copy the value stored in the original sprite, clone 1 gets digit 1, clone 2 gets digit 2, ...
change x by (15) // distance between each clone
end
set [digit v] to [0] // the original sprite will have the digit of 0 so it won't run like the clones
hide
broadcast [update clones v]
when I receive [update clones v] // run this broadcast at any time to update the numbers
if <not <(digit) = [0]>> then // digit 0 is the original, we don't want it running this script
switch costume to (letter (digit) of (number)) // the number variable is the variable you want to display with the clones
end
Edit: the above comments got cut off. They say:
“each clone will copy the value stored in the original sprite, clone 1 gets digit 1, clone 2 gets digit 2, …”
“the number variable is the variable you want to display with the clones”
Also, another thing to add: this same thing works with displaying text! You just have to add costumes for all the letters.
Last edited by awesome-llama (Nov. 28, 2021 17:24:12)
- craftman12
-
Scratcher
51 posts
Sprite Variables
just use text engineWhat Do You Mean By “Text Engine”
- MrNanners
-
Scratcher
100+ posts
Sprite Variables
Look up “pen text engine” and use the one by djpro. It's what I use for many things. IMO clone text engines, although you can do more with them, aren't as good as pen text enginesjust use text engineWhat Do You Mean By “Text Engine”
Last edited by MrNanners (Nov. 29, 2021 22:13:32)
- Discussion Forums
- » Help with Scripts
-
» Sprite Variables