Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Speed of repeat until
- porpolsemicolon
-
New Scratcher
2 posts
Speed of repeat until
Sorry if the block formatting is wrong, this is my first post. The last repeat FAST block is supposed to be custom block.
Hi! I was having trouble with a numbering-thingy in my game. I want it to be fast, but if I make it with the without refresh thingy in the custom block, it does it ALL in one frame.
Itll be easier to explain with blocks
This is what I currently have:
Hi! I was having trouble with a numbering-thingy in my game. I want it to be fast, but if I make it with the without refresh thingy in the custom block, it does it ALL in one frame.
Itll be easier to explain with blocks
This is what I currently have:
define repeat FAST
repeat until <(money) = ((buy before money) - (item price))>
change (money) by (-1)
when this sprite clickedThe problem is that if I add a wait block:
set (buy before money) to (money)
broadcast [item bought]
repeat FAST
define repeat FASTno matter how long I make the wait, it gets really laggy (like the number only changes every SECOND). But I do not want it to all happen in one frame. Of course, I can just not use the custom block, but that is still too slow.
repeat until <(money) = ((buy before money) - (item price))>
change (money) by (-1)
wait (0.000001) secs
Last edited by porpolsemicolon (June 25, 2026 11:56:26)
- awesome-llama
-
Scratcher
1000+ posts
Speed of repeat until
Scratch doesn't really let you make loops run somewhere between the targeted 30 FPS and all-in-one-frame. It's better to make calculations that depend on the elapsed time, rather than trying to control timing to fit your calculations.
If you wanted a fixed rate that money should be changed by, for example 600 per second (so 20 per frame), you could do something like this:
If you wanted a fixed rate that money should be changed by, for example 600 per second (so 20 per frame), you could do something like this:
set [amount to deduct v] to (item price)
repeat until <(amount to deduct) < (0)>
change [money v] by (-20)
change [amount to deduct v] by (-20)
end
change [money v] by (amount to deduct)
set [amount to deduct v] to [0]
Last edited by awesome-llama (Today 11:33:50)
- dem_bot
-
Scratcher
1000+ posts
Speed of repeat until
I would recommend keeping two money variables. One is the actual amount of money, whilst the other one is the display amount. When you buy something, you look at the actual amount and just directly deduct the full price of that. A different part of the code will do the money display, where you can do something like:
forever
change [disp money v] by (((money) - (disp money)) / (0.1))
set [disp money v] to (round(disp money))
- THEIMPORTANT
-
Scratcher
1000+ posts
Speed of repeat until
A workaround for the waitblock is:
It doesn't lag in refresh custom blocks either.
say [] for (duration) secs
It doesn't lag in refresh custom blocks either.
- porpolsemicolon
-
New Scratcher
2 posts
Speed of repeat until
oh i thought i deleted this i fixed it a while ago
Last edited by porpolsemicolon (Today 06:50:07)
- Discussion Forums
- » Help with Scripts
-
» Speed of repeat until