How to make a repeat loop with a wait time

Started by RedWirePlatinum on

Topic category: User side tutorials

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to make a repeat loop with a wait time

A while ago, I made a post asking if you could include a wait time in the "repeat [number] times" block.. well, it turns out you *CAN* do a wait time for this... and the solution was actually quite simple. I kinda feel dumb for not thinking of this before.

code example

Make sure you have the iterator variable outside of the "wait [number] ticks" code block because obviously, local variables do not work in it. Also, make the iterator addition block the last thing that happens in a repeat block, so the first iteration happens instantly.

For example, this is for my /cmdrepeat command, so currently typing "/cmdrepeat 30 summon sheep" would summon 30 sheep within 1.5 seconds.

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
If you're going to do a loop…
Mon, 03/20/2023 - 03:09

If you're going to do a loop within a loop (for example: for each entity AND repeat [number] times), reset the iterator to 0 before doing the "repeat [number] times" thing like so:

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
^ This just makes it so all…
Mon, 03/20/2023 - 04:27

^ This just makes it so all entities get affected at once instead of one entity at a time

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Unfortunately I have no idea…
Mon, 03/20/2023 - 21:04

Unfortunately I have no idea how to break the loop with a wait time AAAAAAGH

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Okay nevermind, actually DO…
Tue, 03/21/2023 - 04:47

Okay nevermind, actually DO make the iterator addition block the first thing the happens, apparently waiting 0 ticks then doing something simply doesn't do it.. oops

Joined Jul 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks so much for making…
Fri, 08/23/2024 - 19:05

Thanks so much for making this!