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

Coroutines

Summary

Use Coroutines in Reactor server scripts. A coroutine is a function suspend (yield) it's execution and resume it later. They are useful for scripting behaviours that take place over many frames, such as NPC behaviours that involve waiting.

Description

ksCoroutine is the equivalent to Unity Coroutine for server scripts. Use yield return null; to suspend execution until the next frame.

using KS.Reactor;
using KS.Reactor.Server;

/**
 * Wait one second then log out a message.
 */
public class srRoom : ksServerEntityScript
{
    public override void Initialize()
    {
        Room.Coroutines.Start(WaitOneSecond());
    }

    private IEnumerator WaitOneSecond()
	{
		yield return Room.Coroutines.Sleep(1f);
		ksLog.Info("1 second has passed");
	}
}

Last updated