Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi! I have a custom entity and I wish it would run some logic (e.g. play some sound) in every 2 seconds and some other logic in every half a second. For that I’m at the moment using 2 different timers. In entity baseTick function (runs every tick, 20 times per second):

entity.getPersistentData().putInt("timer1", entity.getPersistentData().getInt("timer1") + 1);
if (entity.getPersistentData().getInt("timer1") >= 40) {// evry 2 seconds
	entity.getPersistentData().putInt("timer1", 0);
}
if (entity.getPersistentData().getInt("timer1") == 1) {
	//Run logic 1
}

Then I have second timer for the half second logic. Since both timers logic will run on every second it’s not very efficient. And it gets worse as I add more timers.

Is there a way to replace this timer with something else that would be more efficient? Thanks. 

Edited by RInventor7

5 hours ago, RInventor7 said:

Hi! I have a custom entity and I wish it would run some logic (e.g. play some sound) in every 2 seconds and some other logic in every half a second.

Just use one timer and check for every 10 ticks (0.5s) and every 40 ticks (2s). Unless there is something that would desync the timers, it makes no sense to do otherwise.

Additionally, just use a field on the entity itself, don't read/write from persistent data every tick.

  • RInventor7 changed the title to More efficient entity timers? [SOLVED]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.