eternal_despair
eternal_despair

Reputation: 1

Algorithm for Scratch

I need help with a Scratch algorithm that increments its step by 1 each time, first it takes 1 step, then 2 steps, then 3 steps and last 4 steps. you have commands like step forward 1 time, repeat 2 to 11 times, mine 1 time, assign variable = 0 to 4, change variable to 2 to 4 [enter image description here](https://i.sstatic.net/KtZ1I.png) Conditions of the problem: Each time you need to take one step more than before. How can we do it? And also the limitation of commands ...

I need help with a Scratch algorithm that increments its step by 1 each time, first it takes 1 step, then 2 steps, then 3 steps and last 4 steps. you have commands like step forward 1 time, repeat 2 to 11 times, mine 1 time, assign variable = 0 to 4, change variable to 2 to 4 [enter image description here](https://i.sstatic.net/KtZ1I.png)

Upvotes: 0

Views: 395

Answers (1)

user18383414
user18383414

Reputation:

Assuming you have operators available:

  1. Make a variable for the count of steps and set it to 1 at the start of the script.
  2. Make a "step forward (variable) steps" block.
  3. Make a "set (variable) to (variable) + 1" block and put it underneath.
  4. Make a "wait (short duration of time) seconds" block and put it underneath.
  5. Put these three blocks into a 4-time loop.

What happens within the script (in chronological order)

The variable is set to 1. The loop will occur for the first time when triggered, one step forward will be made, the variable will be set to variable + 1 (= 1 + 1 = 2), and the sprite will wait for a short duration of time before repeating to prevent moving only once. After this duration, the loop repeats again with the new value of the variable, until the count is fulfilled and your sprite will end up in the position you want the way you want.

You can, of course, change how many steps should be taken at the start and how many times should the loop repeat to make more and more steps, however, this will do for what you requested.

Upvotes: 1

Related Questions