Redscript
HomeGitHubDiscord
  • Home
  • Getting Started
    • Downloads
    • Setup for VSCode
    • Setup for JetBrains IDEs
    • How to start REDscripting
      • Step 1: Mod structure
      • Step 2: Finding the right class
  • Language
    • Intro
      • REDscript in 2 minutes
      • How to create a hook
        • Things to hook
    • Language Features
      • Intrinsics
      • Loops
      • Strings
      • Modules
      • Annotations
      • Conditional compilation
      • Configurable user hints
    • Built-in Types
    • Built-in Functions
      • Math
      • Random
      • Utilities
  • References and examples
    • Common Patterns
      • Safe downcasting
      • Class constructors
      • Hash maps
      • Heterogeneous array literals
      • Scriptable systems (singletons)
      • DelaySystem and DelayCallback
      • Generic callbacks
      • Persistence
    • Logging
    • UI Scripting
      • Logging Widget Trees
      • Popups
    • Vehicle system
    • Weapons
    • Codeware callbacks
      • Scriptables comparison
    • Libraries
    • Gameplay
      • Sleeping and Skipping Time
  • Help
    • Community
    • Troubleshooting
Powered by GitBook
On this page
  1. References and examples
  2. Common Patterns

DelaySystem and DelayCallback

PreviousScriptable systems (singletons)NextGeneric callbacks

Last updated 11 months ago

Was this helpful?

CtrlK

Was this helpful?

DelaySystem is a class that allows async call of DelayCallback after the set amount of time has passed.

This is how to create a custom DelayCallback:

public class CustomCallback extends DelayCallback {
  // all the data that your Call function needs
  private let myInt: Int32;

  public func Call() {
    // custom function that i want to be called when the specified time has passed
    if this.myInt > 1 {
      FTLog("Input is bigger than 1");
    } else {
      FTLog("Input is smaller than 1");
    }
  }

  public static func Create(inputInt: Int32) -> ref<CustomCallback> {
    // use this way to create your Callback class in one line
    let self = new CustomCallback();

    self.myInt = inputInt;
    return self;
  }
}

and this is how you can use the DelaySystem to call the Callback function with a delay:

let delaySystem = GameInstance.GetDelaySystem(GetGameInstance());
let inputInt: Int32 = 2;
let delay: Float = 1.0;
let isAffectedByTimeDilation: Bool = false;

delaySystem.DelayCallback(CustomCallback.Create(inputInt), delay, isAffectedByTimeDilation);

You can take a look at Generic callbacks for more use cases.