Skip to main content
Skip to main content

PlaceableLightsStateEvent

PlaceableLightsStateEvent

Description

Event for toggling placeable light state

Parent

Event

Functions

emptyNew

Description

Create instance of Event class

Definition

emptyNew()

Return Values

anyselfinstance of class event

Code

function PlaceableLightsStateEvent.emptyNew()
return Event.new( PlaceableLightsStateEvent _mt)
end

new

Description

Create new instance of event

Definition

new(table object, integer groupIndex, boolean isActive)

Arguments

tableobjectobject
integergroupIndexindex of group
booleanisActiveis active

Code

function PlaceableLightsStateEvent.new(placeable, groupIndex, isActive)
local self = PlaceableLightsStateEvent.emptyNew()
self.placeable = placeable
self.groupIndex = groupIndex
self.isActive = isActive
return self
end

readStream

Description

Called on client side on join

Definition

readStream(integer streamId, Connection connection)

Arguments

integerstreamIdstreamId
Connectionconnectionconnection

Code

function PlaceableLightsStateEvent:readStream(streamId, connection)
self.placeable = NetworkUtil.readNodeObject(streamId)
self.groupIndex = streamReadUIntN(streamId, PlaceableLights.MAX_NUM_BITS)
self.isActive = streamReadBool(streamId)
self:run(connection)
end

run

Description

Run action on receiving side

Definition

run(Connection connection)

Arguments

Connectionconnectionconnection

Code

function PlaceableLightsStateEvent:run(connection)
if not connection:getIsServer() then
g_server:broadcastEvent( self , false , connection, self.placeable)
end

if self.placeable ~ = nil and self.placeable:getIsSynchronized() and self.placeable.setGroupIsActive ~ = nil then
self.placeable:setGroupIsActive( self.groupIndex, self.isActive, true )
end
end

sendEvent

Description

Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients

Definition

sendEvent(table lightSystem, integer groupIndex, boolean isActive, )

Arguments

tablelightSystemlightSystem object
integergroupIndexindex of group
booleanisActiveis active
anynoEventSend

Code

function PlaceableLightsStateEvent.sendEvent(placeable, groupIndex, isActive, noEventSend)
if noEventSend = = nil or noEventSend = = false then
if g_server ~ = nil then
g_server:broadcastEvent( PlaceableLightsStateEvent.new(placeable, groupIndex, isActive), nil , nil , placeable)
else
g_client:getServerConnection():sendEvent( PlaceableLightsStateEvent.new(placeable, groupIndex, isActive))
end
end
end

writeStream

Description

Called on server side on join

Definition

writeStream(integer streamId, Connection connection)

Arguments

integerstreamIdstreamId
Connectionconnectionconnection

Code

function PlaceableLightsStateEvent:writeStream(streamId, connection)
NetworkUtil.writeNodeObject(streamId, self.placeable)
streamWriteUIntN(streamId, self.groupIndex, PlaceableLights.MAX_NUM_BITS)
streamWriteBool(streamId, self.isActive)
end