Wait not working properly, or maybe I'm not understanding correctly

Started by Wooddent on

Topic category: Help with modding (Java Edition)

Last seen on 01:40, 11. Feb 2024
Joined Oct 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Wait not working properly, or maybe I'm not understanding correctly

I'm working on a procedure to increase energy on an energy GUI bar, but the wait time only works once and now makes it so that if any energy decreases, it instantly fills up again. Here is the image of the procedure: https://imgur.com/MM70r0g 

Last seen on 05:10, 3. Dec 2023
Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This is something I've…
Mon, 07/17/2023 - 20:51

This is something I've struggled with too. The issue is you have it on the global "on player tick update" so every tick, it's waiting 140 ticks and then doing your procedure, so once you reach the 140 ticks the first time, it will always be a 1 tick delay after the initial 140 ticks. 

I found that the solution to this is creating something that locks the code, and then you can create something that unlocks it.

Here is an example of code: https://imgur.com/a/Q10Dw4T - For simplicity I turned your global into a local, but you should leave it as a global. If you would like you can also create a global player persistent instead of the NBT data.