Skip to content

Get Sansar

Script API

Timer

Where: Client
More page actions

For the complete documentation index, see llms.txt. This page is also available as Markdown.

Class Namespace Sansar.Script

The Timer class is a static class that manages timer events for a script.

public static class Timer

Remarks

The time the event is generated is guaranteed to be no less than the given duration, but may be more depending on system load.

Members at a glance

KindMembers
MethodsCancel · Create

Methods

Cancel

Deprecated
[System.Obsolete("Named timers are deprecated. Use the IEventSubscription returned from Timer.Create to cancel a timer.", false)] public static void Cancel(string name)

Cancels a repeating timer.

ParameterTypeDescription
namestringName of the timer to cancel.
Remarks

If no timer with the given name exists, a ArgumentException will be thrown by the invocation.

Create

Added in 32.0.0
public static IEventSubscription Create(     double initialDurationSeconds,     Action handler )

Generates a one time event.

ParameterTypeDescription
initialDurationSecondsdoubleThe minimum duration to elapse before the event is generated in seconds.
handlerActionThe Action to be called when the time has elapsed.

Returns: IEventSubscription

public static IEventSubscription Create(     TimeSpan initialDuration,     Action handler )

Generates a one time event.

ParameterTypeDescription
initialDurationTimeSpanThe minimum duration to elapse before the event is generated.
handlerActionThe Action to be called when the time has elapsed.

Returns: IEventSubscription

Added in 32.0.0
public static IEventSubscription Create(     double initialDurationSeconds,     Action handler,     bool persistent )

Generates a one time event.

ParameterTypeDescription
initialDurationSecondsdoubleThe minimum duration to elapse before the event is generated in seconds.
handlerActionThe Action to be called when the time has elapsed.
persistentboolSet to true to continue generating events, false to stop after the first one

Returns: IEventSubscription

Added in 32.0.0
public static IEventSubscription Create(     double initialDurationSeconds,     double repeatDurationSeconds,     Action handler )

Generates a repeating event with an initial duration and a repeat duration.

ParameterTypeDescription
initialDurationSecondsdoubleThe minimum duration to elapse before the event is generated in seconds.
repeatDurationSecondsdoubleAfter the initial duration, events will be generated at this interval in seconds.
handlerActionThe Action to be called when the time has elapsed.

Returns: IEventSubscription

public static IEventSubscription Create(     TimeSpan initialDuration,     Action handler,     bool persistent )

Generates a one time event.

ParameterTypeDescription
initialDurationTimeSpanThe minimum duration to elapse before the event is generated.
handlerActionThe Action to be called when the time has elapsed.
persistentboolSet to true to continue generating events, false to stop after the first one

Returns: IEventSubscription

public static IEventSubscription Create(     TimeSpan initialDuration,     TimeSpan repeatDuration,     Action handler )

Generates a repeating event with an initial duration and a repeat duration.

ParameterTypeDescription
initialDurationTimeSpanThe minimum duration to elapse before the event is generated.
repeatDurationTimeSpanAfter the initial duration, events will be generated at this interval.
handlerActionThe Action to be called when the time has elapsed.

Returns: IEventSubscription

Deprecated
[System.Obsolete("Named timers are deprecated. Use the IEventSubscription returned from Timer.Create to cancel a timer.", false)] public static void Create(     TimeSpan initialDuration,     TimeSpan repeatDuration,     Action handler,     string name )

Generates a repeating event with an initial duration and a repeat duration. The event will continue as long as the script is active or until Timer.Cancel is called.

ParameterTypeDescription
initialDurationTimeSpanThe minimum duration to elapse before the event is generated.
repeatDurationTimeSpanAfter the initial duration, events will be generated at this interval.
handlerActionThe Action to be called when the time has elapsed.
namestringA short string to identify this Timer.
Remarks

At most, one event will be generated per server frame, even if the duration is significantly shorter than the server frame time. Only the first 8 characters of the name are significant. Multiple timers with the same name are allowed. When Timer.Cancel is called the first timer with a matching name is stopped.

Used in examples

Generated from the Sansar 47.10.0 client ScriptApi snapshot.