#system.runTimeout() alternative

1 messages · Page 1 of 1 (latest)

turbid cipher
#

a common problem ive encountered with system.runTimeout() is that it breaks when leaving the world, cancelling any scheduled code. so i made an alternative Scheduler class to solve the problem.
https://gist.github.com/Dismalitie/95c06e5b79e8ccbd067363b7e846cd8f

Scheduler.scheduleFunc(delay, func) isnt perfect, and has some limitations:

  1. func must be a lambda function (() => {})
  2. code run through Scheduler.scheduleFunc() is in its own scope, so you'll have to re-import stuff
  3. lambda function code cant exceed the character limit of world dynamic properties

so to solve some of those problems, you can use Scheuduler.scheduleScriptEvent(). just make sure the event is defined at runtime.

important notes:

  • Scheduler._initialize() must be run before scheduling anything
  • if using Scheduler.scheduleFunc(), you must have the script_eval capability enabled in your bp's manifest
Gist

GitHub Gist: instantly share code, notes, and snippets.

foggy panther
#

Nice

grand stratus
foggy panther