Discuss Scratch

Axolotl_KH_Sakurako
Scratcher
13 posts

I need help with movement

I've never coded a game before, but I have a script that looks like this.
when [ Right Arrow] key pressed
switch costume to [Starter Cat Right]
repeat (10)
move (5) steps

end

I tested this out, and whenever I hold down the key it only moves once, restarts, and then continue to moves. Do I just need to do more coding, or do I have to update the script to fix this? It's not that big of a problem, but I just want to make the game more polished, and better.

Last edited by Axolotl_KH_Sakurako (Dec. 26, 2024 22:40:25)

FoolsGuld
Scratcher
100+ posts

I need help with movement

I would recommend switching to a looping system, like this one:
when green flag clicked
forever
if <key [Right Arrow v] pressed?> then
switch costume to [Starter Cat Right v]
move (5) steps
end
end

With this script, it will continuously check if you are pressing down the right arrow, and if you are, it will switch the costume and move five steps. You can tweak this by changing the amount of steps you move each time, or by adding an interval in between movements. I hope this helps!
NPLol39-2_
Scratcher
100+ posts

I need help with movement

Yeah, a looping system would work well!
when [right arrow v] key pressed
switch costume to [starter cat right v] //switches costume
repeat until <not <key [right arrow v] pressed?>> //keeps moving 5 steps until right arrow key is released
move (5) steps
wait () secs //if you want the sprite to go a specific speed
end
If you want it to move 50 steps or less, try:
when [right arrow v] key pressed
set [foo v] to [0]
switch costume to [starter cat right v] //switches costume
repeat until <<not <key [right arrow v] pressed?>> or <(foo) = [10]>> //keeps moving 5 steps until right arrow key is released, or until foo is 10
move (5) steps
wait () secs //if you want the sprite to go a specific speed
change [foo v] by (1)
end

Powered by DjangoBB