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

I'm sure I'm doing something silly here, but I'm starting a timer in an NPC's init callback, and when I clone that NPC, it seems like all subsequent copies are having their timer callback invoked immediately.

 

It works fine if I clone the NPC before without enabling the script: when I spawn three, and enable each NPC's script separately, it works how I would expect it to.

 

What am I doing wrong? I assume that cloning is not how I should be doing this, but I don't know how to "save" an npc with scripts turned on.

 

My script:

 

var LIFESPAN = 255;
var DEATH_ID = 0;

function init(event){
    event.npc.say("I live...");
    event.npc.getTimers().start(DEATH_ID, LIFESPAN, false);
}

function timer(event){
    if (event.id === DEATH_ID) {
        event.npc.say("...now I die");
        event.npc.despawn();
    }
}

 

The goal is to have an NPC automatically despawn on a timer after they spawn.

  • 2 weeks later...

That is a good question because if you do it separately it dose not seem to be global. But if you clone them it seems to be  the same timer????

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.