Repository navigation
EN API UO Wait
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Home · C# · IDE · UO API · A–Z · Examples · Languages
void UO.Wait(object? waitTimeMS);Pauses the current script for the specified number of milliseconds. Useful between repeated status checks to prevent the script from running in a continuous loop.
-
waitTimeMS— Integer time in milliseconds: 1000 = one second. Use 0..2147483647. This is not the number of steps, not the seconds, and not the server confirmation timeout.
void - no result. Call on a separate line. The end of the delay does not mean that the object has moved, the spell has completed, or the connection has been established: check the desired state separately.
- Zero creates no real delay and is not suitable as a pause in a fast loop. Negative time does not mean infinity: UO.Wait reduces it to 0; UO.Wait/sleep can reject it with active callbacks, and in the client bridge without them it will not wait. For a portable script, use only non-negative times.
UO.Wait(100);
// For an asynchronous script, use the host helper:
await WaitAsync(100);Each example can be saved as a separate file .csx and run in IDE. The UO object and wait functions provide the host of the current game session. Replace demo serial names, coordinates and addresses with your own.
Run this code as a separate .csx file. Arguments appear directly in the call; replace demonstration names, serials and addresses with your own.
The command is a separate statement. The message before it marks the start of the call; it does not confirm a server action.
UO.Print("Calling UO.Wait");
UO.Wait(250);Parameters and execution flow:
- 250 - quarter of a second. The next line is executed after waiting; The Delay complete message is the text of the example, not the returned result.
UO.Wait(250);
UO.Print("Delay complete");Parameters and execution flow:
- WaitForOnline is fully declared in this script. The argument 20 means a maximum of twenty pauses of 250 ms. The connection is checked before pauses and again after the last one. The helper returns the state Connected (1/0); The wait command itself does not return anything and does not connect to the server.
return RunScenario();
object? RunScenario()
{
return WaitForOnline(20);
return null;
}
dynamic WaitForOnline(dynamic checks)
{
while (Truth(checks > 0))
{
if (Truth(UO.Connected()))
{
return 1;
}
UO.Wait(250);
checks = checks - 1;
}
return UO.Connected();
}
bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;Parameters and execution flow:
- The loop makes exactly three weight readings. Between readings there are two pauses of 500 ms, after the last there is no pause. A message is printed the first time it is read and when the weight changes. The previous variable stores the value to compare, rather than adjusting the game weight.
return new ScriptScenario(UO, WaitAsync, Args, Cancellation, Checkpoint).RunScenario();
class ScriptScenario
{
private readonly global::ClassicUO.CSharp.CSharpGameApi UO;
private readonly Func<int, Task> WaitAsync;
private readonly string[] Args;
private readonly CancellationToken Cancellation;
private readonly Action Checkpoint;
public ScriptScenario(global::ClassicUO.CSharp.CSharpGameApi api, Func<int, Task> wait, string[] args, CancellationToken cancellation, Action checkpoint)
{
UO = api;
WaitAsync = wait;
Args = args;
Cancellation = cancellation;
Checkpoint = checkpoint;
}
public object? RunScenario()
{
var previous = -1;
var checks = 0;
while (Truth(checks < 3))
{
var weight = UO.Weight();
if (Truth(weight != previous))
{
UO.Print("Weight: " + Convert.ToString(weight));
previous = weight;
}
checks = checks + 1;
if (Truth(checks < 3))
{
UO.Wait(500);
}
}
return null;
}
bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.
Parameters: waitTimeMS (Any)
Result: void / Unit.
During a call:
-
ClassicUO.CSharp.CSharpScriptGlobals.WaitAsync. -
InjectionScript.Runtime.InjectionApiUO.ExecuteClientApiCompatibility. -
InjectionScript.Runtime.InjectionApiUO.WaitWithEvents:WaitWithEvents(Arg(0)). -
InjectionScript.Runtime.InjectionApiUO.ExecuteClientApiCompatibility::Arg:Arg(0).
Internal implementation code; this is not a standalone script.
public async Task WaitAsync(int milliseconds)
{
ArgumentOutOfRangeException.ThrowIfNegative(milliseconds);
Checkpoint();
// Short slices allow Pause to suspend further script progress promptly.
int remaining = milliseconds;
while (remaining > 0)
{
int slice = Math.Min(remaining, 25);
await Task.Delay(slice, Cancellation).ConfigureAwait(false);
Checkpoint(); remaining -= slice;
}
}Internal implementation code; this is not a standalone script.
case "wait": WaitWithEvents(Arg(0)); return InjectionValue.Unit;ClassicUO — Bad Newbie & C# Scripts IDE