Class VirtualValue

(Abstract) A container for a single value.

A VirtualValue (or VV for short) has a single contained value. This value is initially nil, although implementations should set a sensible default (0, false, "", etc). It has useful tools which allow you to observe and manipulate the value:

Additionally, the onChange(newValue) event fires immediately after the value is set though any means.

Replication

Server-side replication of a VirtualValue is easily implemented through a Server, constructable through the server method. On the client, use the client method and provide the remotes container. Finally, open the server to begin replication. You can set up fine-grain replication rules within the Permissions of the Server.

Implementations:

See also:

  • DynamicVirtualValue, an abstract subclass which can add VirtualValue as children to stack their values

Events

VirtualValue.onChange Fires when the contained value changes

Functions

VirtualValue.new(expectedType) Constructs a new VirtualValue which contains a certain expectedType

Metamethods

VirtualValue:__tostring() Returns the current value passed to tostring

Methods

VirtualValue:cleanup() Releases all resources used by this VirtualValue
VirtualValue:set(value) Sets the contained value; if different than current, fires onChange
VirtualValue:get() Gets the contained value
VirtualValue:value([newValue]) Set/get the contained value
VirtualValue:listen(func) Call a function with the contained value, then again every time the contained value changes
VirtualValue:bind(object, property) Set object[property] to the currently contained value, then again every time the contained value changes
VirtualValue:getServerClass() Returns the class used by VirtualValue:server
VirtualValue:server(...) Constructs a Server to replicate the contained value to various clients
VirtualValue:client(remotes) Constructs a Client to replicate the contained value to/from the server
VirtualValue:serialize() Convert the contained value into a payload that can be sent through Roblox's serialization used by BindableFunction, RemoteFunction, etc.
VirtualValue:deserialize(payload) Set the contained value to the provided payload from serialize


Events

VirtualValue.onChange
Fires when the contained value changes
  • newValue The new contained value

Functions

Methods
VirtualValue.new(expectedType)
Constructs a new VirtualValue which contains a certain expectedType

Parameters:

  • expectedType string expected type (or table of expected types) to be contained

Metamethods

VirtualValue:__tostring()
Returns the current value passed to tostring

Returns:

    string The current value as a string

Methods

VirtualValue:cleanup()
Releases all resources used by this VirtualValue
VirtualValue:set(value)
Sets the contained value; if different than current, fires onChange

Parameters:

  • value The value to store
VirtualValue:get()
Gets the contained value

Returns:

    The contained value
VirtualValue:value([newValue])
Set/get the contained value

Parameters:

  • newValue The new value to set, or nil to keep the current value (optional)

Returns:

    The contained value
VirtualValue:listen(func)
Call a function with the contained value, then again every time the contained value changes

Parameters:

  • func function The listener function

Returns:

    Connection When disconnected, func from being called when the value changes
VirtualValue:bind(object, property)
Set object[property] to the currently contained value, then again every time the contained value changes

Parameters:

  • object A table, userdata, etc which can accept [property] = ...
  • property string The index on object to set

Returns:

    Connection When disconnected, stops func from being called when the value changes
VirtualValue:getServerClass()
Returns the class used by VirtualValue:server

Returns:

    The Server class
VirtualValue:server(...)
Constructs a Server to replicate the contained value to various clients

Parameters:

Returns:

    Server The newly constructed server
VirtualValue:client(remotes)
Constructs a Client to replicate the contained value to/from the server

Parameters:

Returns:

    Client
VirtualValue:serialize()
Convert the contained value into a payload that can be sent through Roblox's serialization used by BindableFunction, RemoteFunction, etc. This default implementation sends the data unchanged; custom types will need custom serilization.

Returns:

    The data payload
VirtualValue:deserialize(payload)
Set the contained value to the provided payload from serialize

Parameters:

  • payload The data payload
generated by LDoc 1.4.6 Last updated 2021-01-21 07:22:00