ParelVRDocs
Player site

Scripting / Reference

Core

Types in the ParelVR.Volt namespace.

VoltBehaviour#

ParelVR.Volt.VoltBehaviour behaviour

Base class of every world script. A class that derives from it is compiled by the VoltCS compiler into Volt bytecode and run by VoltVM inside ParelVR; Unity never runs its code. Override the On... methods to receive events, and mark fields with VoltSynced to share them with other players.

VoltBehaviour properties#

bool IsOwner { get; }

True when the local player owns this object.

VoltPlayer Owner { get; }

The player who owns this object.

bool enabled { get; set; }

Whether this behaviour receives events. A disabled behaviour still keeps its state.

VoltGameObject gameObject { get; }

The object this behaviour is attached to.

string name { get; }

The name of the object this behaviour is attached to.

VoltTransform transform { get; }

The transform of the object this behaviour is attached to.

VoltBehaviour methods#

T GetComponentInChildren()

Finds a component, or another behaviour, on this object or any of its children.

T GetComponentInParent()

Finds a component, or another behaviour, on this object or any of its parents.

T GetComponent()

Finds a component, or another behaviour, on the same object. Returns null when there is none.

object GetVariable(string fieldName)

Reads a public or VoltExpose field of this behaviour by name. Returns null when there is no such field.

void RequestSerialization()

Asks for this behaviour's synced fields to be sent to everyone. Only the owner's request has an effect.

void SendCustomEvent(string eventName)

Calls a public or VoltEvent method of this behaviour by name. Does nothing when there is no such method.

void SendCustomEventDelayedFrames(string eventName, int frames)

Calls a method by name after a number of frames.

void SendCustomEventDelayedSeconds(string eventName, float seconds)

Calls a method by name after a delay in seconds.

void SendNetworkEvent(VoltNetworkTarget target, string eventName, object[] arguments)

Runs a VoltNetworkEvent method of this behaviour on other players' clients. The method name must be a constant (use nameof); the compiler turns it into a numeric id. Up to eight arguments of syncable types.

void SendNetworkEvent(VoltPlayer target, string eventName, object[] arguments)

Runs a VoltNetworkEvent method of this behaviour on one player's client.

void SendNetworkEventById(VoltNetworkTarget target, int eventId, object[] arguments)

What SendNetworkEvent compiles to: the event is named by its id.

void SendNetworkEventToPlayerById(VoltPlayer target, int eventId, object[] arguments)

What SendNetworkEvent to one player compiles to: the event is named by its id.

void SetOwner(VoltPlayer player)

Hands this object to another player. Only the current owner or the instance master can do this.

bool SetVariable(string fieldName, object value)

Writes a public or VoltExpose field of this behaviour by name. Returns false when the field is missing or the value has the wrong type.

VoltCoroutine StartCoroutine(IEnumerator routine)

Starts a coroutine. It runs until its first yield before this call returns.

void StopAllCoroutines()

Stops every coroutine this behaviour started.

void StopCoroutine(VoltCoroutine routine)

Stops a coroutine this behaviour started.

void TakeOwnership()

Makes the local player the owner of this object. OnOwnershipRequest of the current owner can refuse.

VoltCoroutine#

ParelVR.Volt.VoltCoroutine class

A running coroutine. Coroutines are state machines inside VoltVM: they never run on another thread, and a world can have at most 512 of them at a time.

VoltCoroutine properties#

bool IsDone { get; }

True once the coroutine ran to its end.

bool IsRunning { get; }

True while the coroutine has not finished and was not stopped.

VoltCoroutine methods#

static VoltCoroutine Start(VoltBehaviour owner, IEnumerator routine)

Starts a coroutine on a behaviour. The same as calling StartCoroutine on it.

void Stop()

Stops the coroutine. It does not continue after its current yield.

static void StopAll(VoltBehaviour owner)

Stops every coroutine of a behaviour.

VoltDebug#

ParelVR.Volt.VoltDebug static

Messages for the creator. They go to the Volt Console in the editor and to the world log in ParelVR.

VoltDebug methods#

static void Assert(bool condition, string message)

Writes an error when a condition is false.

static void Log(object message)

Writes a message.

static void LogError(object message)

Writes an error. The script keeps running.

static void LogWarning(object message)

Writes a warning.

VoltError#

ParelVR.Volt.VoltError enum

Why a web request, a storage request or a purchase did not succeed.

Value Meaning
None (0)
InvalidArgument (1) The address or the key is not well formed.
NotPermitted (2) The world is not allowed to do this, or the player has switched it off.
DomainNotAllowed (3) The address is not on the world's list of allowed domains.
RateLimited (4) Too many requests in a short time.
TooLarge (5) The request or the answer is larger than the limit.
Timeout (6) No answer arrived in time.
NetworkError (7) The connection failed.
HttpError (8) The server answered with an error status.
NotFound (9) There is no value for the key.
Unavailable (10) The service is not available right now.

VoltEvents#

ParelVR.Volt.VoltEvents static

A world-wide event bus: one call reaches every script without holding references to them.

VoltEvents methods#

static void Broadcast(string eventName)

Calls the public method with this name and no parameters on every enabled script of the world that has one, in the order the scripts were created. Only on this client; use SendNetworkEvent to reach others.

VoltProfiler#

ParelVR.Volt.VoltProfiler static

What the world's scripts cost, for scripts that want to adapt to it.

VoltProfiler properties#

static int CoroutineCount { get; }

Number of coroutines that are running.

static long InstructionsLastFrame { get; }

Instructions every script of the world ran in the last frame.

static long MemoryBytes { get; }

Estimate of the memory the world's scripts hold, in bytes.

static float ScriptMsLastFrame { get; }

Milliseconds every script of the world took in the last frame.

VoltRandom#

ParelVR.Volt.VoltRandom static

Random numbers that are the same on every client. The result depends only on the seed and the index, so players who share a seed (a synced field, or VoltRandom.Hash of the instance id) draw the same values without sending them.

VoltRandom methods#

static int Hash(string text)

A seed made from text, the same on every client and every platform.

static float Range(int seed, int index, float min, float max)

A number from min (inclusive) to max (exclusive) for the seed and index.

static int RangeInt(int seed, int index, int min, int max)

A whole number from min (inclusive) to max (exclusive) for the seed and index. min when max is not above min.

static float Value(int seed, int index)

A number from 0 (inclusive) to 1 (exclusive) for the seed and index.

VoltRuntime#

ParelVR.Volt.VoltRuntime static

Facts about the runtime a script is running in.

VoltRuntime properties#

static string ApiVersion { get; }

Version of the Volt API the runtime provides, such as "1.0".

static string BytecodeVersion { get; }

Version of the bytecode format the runtime reads.

static bool IsEditor { get; }

True when the script runs in the Unity editor's simulator instead of ParelVR.

static string Language { get; }

Two-letter code of the player's language, such as "en" or "de". "en" when it is not known.

static string Platform { get; }

The platform ParelVR runs on: "windows" or "android".

VoltTime#

ParelVR.Volt.VoltTime static

Clocks.

VoltTime properties#

static float DeltaTime { get; }

Seconds the last frame took.

static float FixedDeltaTime { get; }

Seconds between physics steps.

static int FrameCount { get; }

Frames since the world loaded.

static int LocalOffsetMinutes { get; }

Difference between this device's local time and UTC in minutes.

static float RealTime { get; }

Real seconds since the world loaded, whatever the time scale.

static float Time { get; }

Seconds since the world loaded.

static long UnixTimeMilliseconds { get; }

Milliseconds since 1 January 1970 UTC, from this device's clock.

static long UnixTimeSeconds { get; }

Seconds since 1 January 1970 UTC, from this device's clock.

VoltWait#

ParelVR.Volt.VoltWait static

The waits a coroutine can yield. Yielding null waits for the next frame.

VoltWait methods#

static VoltWaitInstruction EndOfFrame()

Waits until the end of the frame.

static VoltWaitInstruction FixedUpdate()

Waits for the next physics step.

static VoltWaitInstruction Frames(int frames)

Waits a number of frames.

static VoltWaitInstruction RealSeconds(float seconds)

Waits a number of real seconds, whatever the world's time scale.

static VoltWaitInstruction Seconds(float seconds)

Waits a number of seconds of world time.

static VoltWaitInstruction Until(Boolean> condition)

Waits until a method of this behaviour returns true. Checked once per frame.

static VoltWaitInstruction While(Boolean> condition)

Waits while a method of this behaviour returns true. Checked once per frame.

VoltWaitInstruction#

ParelVR.Volt.VoltWaitInstruction class

What a coroutine yields to say when it wants to continue.