Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to make a custom counter for beginners.
- Susdeveloper
-
Scratcher
49 posts
How to make a custom counter for beginners.
I have no idea where to put this so I decided to put in here.
Source:
https://www.youtube.com/watch?v=OOPNqKE2yuM
This is just a simple tutorial on how to make a number counter.
I'm not talking as in this:
https://scratch.mit.edu/projects/663604414/
Another example is the score in my zombie game once you lose:
https://scratch.mit.edu/projects/577711127/
So, how exactly do you do this?
The answer is actually quite simple too.
This is the code:
First, you paint a new sprite, and paint the numbers on the costumes in this order (costume name doesn't matter):
1, 2, 3, 4, 5, 6, 7, 8, 9, 0.
Don't do 10, do 0 because 10 will make results wierd due to how this script works.
First, you create a new variable with the name of your number value (Coins, Score, Timer ect, make sure it's for all sprites), and another variable called “digits”. Set it for this sprite only.
Then, grab these blocks and assemble like so:
The way the clone script works is multiplying the digits by some integer dependent on the size of your costumes. It uses a lot of tinkering to figure out. It then takes the placement of what your want your x position to be, which also takes a bit of tinkering. After this, if it uses the length of the number value and sees if its smaller than the digits variable. If so, the clone hides. if not, it shows and displays the correct number costume for accuracy. Hope this helped! If this discussion is in the wrong topic, tell me please.
Source:
https://www.youtube.com/watch?v=OOPNqKE2yuM
This is just a simple tutorial on how to make a number counter.
I'm not talking as in this:
when green flag clickedI mean an actual counter with custom fonts. An example is the top GUI in my quiz game here:
set [Number Value v] to [0]
show variable [Number Value v]
https://scratch.mit.edu/projects/663604414/
Another example is the score in my zombie game once you lose:
https://scratch.mit.edu/projects/577711127/
So, how exactly do you do this?
The answer is actually quite simple too.
This is the code:
First, you paint a new sprite, and paint the numbers on the costumes in this order (costume name doesn't matter):
1, 2, 3, 4, 5, 6, 7, 8, 9, 0.
Don't do 10, do 0 because 10 will make results wierd due to how this script works.
First, you create a new variable with the name of your number value (Coins, Score, Timer ect, make sure it's for all sprites), and another variable called “digits”. Set it for this sprite only.
Then, grab these blocks and assemble like so:
when green flag clickedHow this works is every clone has an individual “digits” value. This determines their placement on the stage so you get accurate representation of the variable. Next step is controlling the clones so they switch to the right costume.
show
set [score v] to [whatever, dependent on what you're doing]
set [digits v] to [1]
repeat (the amount of clones you want)
create clone of [myself v]
change [digits v] by (1)
end
hide
when I start as a cloneThis is the entire script! I reccommend you use a different script for controlling the number value variable.
show
forever
go to x: (((digits) * (dependent on size, 30 if about 20 pixels in length)) - (placement of x position)) y: (your y position)
if <(length of [your number value]) < [digits]> then
hide
else
show
switch costume to (letter (digits) of [your number value])
end
end
The way the clone script works is multiplying the digits by some integer dependent on the size of your costumes. It uses a lot of tinkering to figure out. It then takes the placement of what your want your x position to be, which also takes a bit of tinkering. After this, if it uses the length of the number value and sees if its smaller than the digits variable. If so, the clone hides. if not, it shows and displays the correct number costume for accuracy. Hope this helped! If this discussion is in the wrong topic, tell me please.
Last edited by Susdeveloper (April 3, 2022 00:46:38)
- Harakou
-
Scratcher
1000+ posts
How to make a custom counter for beginners.
Hi! It's great that you want to offer some useful tips to other users, but this forum isn't meant for tutorials. Instead, why not create a project and share it in the Show and Tell forum? That way, people can see the scripts you're demonstrating in action, change them easily and remix your project if they want to. 

- Discussion Forums
- » Help with Scripts
-
» How to make a custom counter for beginners.

