While Loop Crash

Started by xmor on

Topic category: Troubleshooting, bugs, and solutions

Joined Apr 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
While Loop Crash

I have a while loop here, yet for some reason it keeps crashing my game. I'm quite new to procedures, but I know it's the while loop because after running the procedure a couple of times, the only time it crashed was when it had contents inside.

 

 

 

Joined Feb 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Could you post a picture of…
Sat, 06/28/2025 - 16:19

Could you post a picture of the loop?

 

But you are probably doing a lot of things really fast, like checking every mob nearby for something.

Joined Apr 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Unfortunately I don't know…
Sat, 06/28/2025 - 18:21

Unfortunately I don't know how, but inside the loop is a wait loop for 20 ticks, and an if statement inside that that checks if the player is in spectator mode, and if they are it switches them to survival.

Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The wait inside the while…
Sat, 06/28/2025 - 18:48

The wait inside the while loop could be the problem.

To try to explain it: Wait delays the current iteration of a procedure, but doesn't stop a new iteration from occuring. While calls a new iteration until the condition is met, which means that if the condition can't be met by something inside the while loop, it will literally call whatever is inside of it infinite times per second, which crashes the game. If the only way to meet the condition of the while loop is delayed, it will call infinite iterations of the contents before the delay finishes, which crashes the game.

My advice would be to use a potion effect, a variable-timer, or an nbt-timer instead of a while loop and a wait block.

Joined Oct 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I wouldn't recommend using a…
Sat, 06/28/2025 - 18:49

I wouldn't recommend using a While Loop for this. Try a counter system like the one I have in this Imgur post. I put a description on how it works there as well.
https://imgur.com/a/Q7L07Ia

I would only use While Loops for things that are complex such as my Player Event Spawner that will spawn specific events 15-45 blocks away from the player at surface level.

https://imgur.com/a/UtGlxiB