API
API
Lua

Defold Learn logo


fusion

Version: stable

FUNCTIONS
fusion.init()
fusion.init_from_settings()
fusion.connect()
fusion.disconnect()
fusion.reconnect()
fusion.start()
fusion.stop()
fusion.get_state()
fusion.get_disconnect_cause()
fusion.join_or_create_room_random()
fusion.join_room_random()
fusion.join_room()
fusion.join_or_create_room()
fusion.create_room()
fusion.leave_room()
fusion.is_connected()
fusion.is_running()
fusion.is_started()
fusion.is_in_room()
fusion.enable_debug()
fusion.register_scene_object()
fusion.spawn()
fusion.despawn()
fusion.register_object()
fusion.unregister_object()
fusion.scene_change()
fusion.rpc()
fusion.on_event()
fusion.get_local_player_id()
fusion.get_owner_id()
fusion.has_authority()
fusion.has_owner()
fusion.want_authority()
fusion.clear_owner_cooldown()
fusion.set_send_rate()
fusion.set_local_send_rate()
fusion.reset_send_rate()
fusion.player_count()
fusion.is_master_client()
fusion.get_rtt()
fusion.network_time_diff()
fusion.set_global_interest_key()
fusion.set_area_interest_key()
fusion.set_user_interest_key()
fusion.set_area_keys()
fusion.add_user_key()
fusion.remove_user_key()
CONSTANTS
OWNERMODE_TRANSACTION
OWNERMODE_PLAYERATTACHED
OWNERMODE_DYNAMIC
OWNERMODE_MASTERCLIENT
OWNERMODE_GAMEGLOBAL
STATE_DISCONNECTED
STATE_CONNECTING
STATE_CONNECTED
STATE_JOININGROOM
STATE_INROOM
STATE_LEAVINGROOM
STATE_DISCONNECTING
DISCONNECT_CAUSE_NONE
DISCONNECT_CAUSE_DISCONNECTBYSERVERUSERLIMIT
DISCONNECT_CAUSE_EXCEPTIONONCONNECT
DISCONNECT_CAUSE_DISCONNECTBYSERVER
DISCONNECT_CAUSE_DISCONNECTBYSERVERLOGIC
DISCONNECT_CAUSE_TIMEOUTDISCONNECT
DISCONNECT_CAUSE_EXCEPTION
DISCONNECT_CAUSE_INVALIDAUTHENTICATION
DISCONNECT_CAUSE_MAXCCUREACHED
DISCONNECT_CAUSE_INVALIDREGION
DISCONNECT_CAUSE_OPERATIONNOTALLOWEDINCURRENTSTATE
DISCONNECT_CAUSE_CUSTOMAUTHENTICATIONFAILED
DISCONNECT_CAUSE_CLIENTVERSIONTOOOLD
DISCONNECT_CAUSE_CLIENTVERSIONINVALID
DISCONNECT_CAUSE_DASHBOARDVERSIONINVALID
DISCONNECT_CAUSE_AUTHENTICATIONTICKETEXPIRED
DISCONNECT_CAUSE_DISCONNECTBYOPERATIONLIMIT
EVENT_OBJECT_READY
EVENT_SUB_OBJECT_CREATED
EVENT_OBJECT_DESTROYED
EVENT_SUB_OBJECT_DESTROYED
EVENT_OBJECT_OWNER_CHANGED
EVENT_OBJECT_PREDICTION_OVERRIDE
EVENT_LOBBY_STATS
EVENT_ROOM_JOINED
EVENT_ROOM_LEFT
EVENT_RPC
EVENT_SCENE_CHANGE
EVENT_DESTROYED_MAP_ACTOR
EVENT_INTEREST_ENTER
EVENT_INTEREST_EXIT
EVENT_FORCED_DISCONNECT
EVENT_FUSION_START
EVENT_CONNECTED
EVENT_DISCONNECTED

Functions

fusion.init()

fusion.init(app_id,app_version)

Initialize Fusion.

PARAMETERS

app_id string
app_version string

fusion.init_from_settings()

fusion.init_from_settings()

Initialize Fusion from game.project settings.

PARAMETERS

None


fusion.connect()

fusion.connect(user,server)

Connect Fusion.

PARAMETERS

user string
server string

fusion.disconnect()

fusion.disconnect()

Disonnect Fusion.

PARAMETERS

None


fusion.reconnect()

fusion.reconnect()

Reconnect Fusion.

PARAMETERS

None


fusion.start()

fusion.start()

Start Fusion sync.

PARAMETERS

None


fusion.stop()

fusion.stop()

Stop Fusion sync.

PARAMETERS

None


fusion.get_state()

fusion.get_state()

Get connection state.

PARAMETERS

None

RETURNS

number State

fusion.get_disconnect_cause()

fusion.get_disconnect_cause()

Get disconnect cause.

PARAMETERS

None

RETURNS

number Cause

fusion.join_or_create_room_random()

fusion.join_or_create_room_random(create_room_options,matchmaking_options)

Join or create random room.

PARAMETERS

create_room_options table
matchmaking_options table

fusion.join_room_random()

fusion.join_room_random(matchmaking_options)

Join random room.

PARAMETERS

matchmaking_options table

fusion.join_room()

fusion.join_room(room_name,join_room_options)

Join room.

PARAMETERS

room_name string
join_room_options table

fusion.join_or_create_room()

fusion.join_or_create_room(room_name,create_room_options,join_room_options)

Join or create room.

PARAMETERS

room_name string
create_room_options table
join_room_options table

fusion.create_room()

fusion.create_room(room_name,create_room_options)

Create room.

PARAMETERS

room_name string
create_room_options table

fusion.leave_room(will_come_back,send_auth_cookie)

Leave room.

PARAMETERS

will_come_back boolean
send_auth_cookie boolean

fusion.is_connected()

fusion.is_connected()

Check if Fusion is connected.

PARAMETERS

None

RETURNS

boolean

fusion.is_running()

fusion.is_running()

Check if Fusion has config and is connected.

PARAMETERS

None

RETURNS

boolean

fusion.is_started()

fusion.is_started()

Check if Fusion is started. Fusion is considered started after a call to. `fusion.start()` has received a `EventOnFusionStart` event.

PARAMETERS

None

RETURNS

boolean

fusion.is_in_room()

fusion.is_in_room()

Check if Fusion is in a room.

PARAMETERS

None

RETURNS

boolean

fusion.enable_debug()

fusion.enable_debug(enable)

Enable/disable debugging.

PARAMETERS

enable boolean

fusion.register_scene_object()

fusion.register_scene_object(scene,factory_url,owner_mode,id)

Register a scene object.

PARAMETERS

scene number
factory_url string
owner_mode number
id string

fusion.spawn()

fusion.spawn(factory_url,position,rotation,scene,owner_mode)

Create a networked game object. This will spawn a game object in the same. Way as when calling factory.create(). The function will also register the spawned object with Fusion as if manually calling register_object()

PARAMETERS

factory_url string
position vector3
Initial position of created game object
rotation quat
Initial rotation of created game object
scene number
The scene to which this object belongs
owner_mode number
Owner mode of spawned object

RETURNS

hash Of the spawned game object

fusion.despawn()

fusion.despawn(id)

Destroy a networked object.

PARAMETERS

id string

fusion.register_object()

fusion.register_object(scene,factory_url,owner_mode,id)

Register an object.

PARAMETERS

scene number
factory_url string
owner_mode number
id string

fusion.unregister_object()

fusion.unregister_object(id)

Unregister a previously registered object.

PARAMETERS

id string

fusion.scene_change()

fusion.scene_change(index,sequence,data)

Change scene.

PARAMETERS

index number
sequence number
data string

fusion.rpc()

fusion.rpc(target_player,data)

Send RPC.

PARAMETERS

target_player number
0 = all, specific PlayerId = targeted
data string

RETURNS

boolean

fusion.on_event()

fusion.on_event(listener)

Set event listener.

PARAMETERS

listener function

fusion.get_local_player_id()

fusion.get_local_player_id()

Get the player id of the local client

PARAMETERS

None

RETURNS

number Player id of the local client

fusion.get_owner_id()

fusion.get_owner_id(id)

Get the player id of the current owner of an object

PARAMETERS

id string
Id of the object to get the owner for

RETURNS

number Player id of the object's owner

fusion.has_authority()

fusion.has_authority(id)

Check if this client has authority over a game object. Use this to decide if user input should be handled or not.

PARAMETERS

id string

RETURNS

boolean Returns true if the client has authority

fusion.has_owner()

fusion.has_owner(id)

Check if an object has an owner

PARAMETERS

id string
Id of the object

RETURNS

boolean If the object has an owner

fusion.want_authority()

fusion.want_authority(claim_ownership,id)

Signal desire for the local client to own an object

PARAMETERS

claim_ownership boolean
id string
Id of the object to own

fusion.clear_owner_cooldown()

fusion.clear_owner_cooldown(id)

Explicitly clear the ownership cooldown

PARAMETERS

id string
Id of the object to clear cooldown for

fusion.set_send_rate()

fusion.set_send_rate(send_rate,id)

Set the send rate of an object. This decided how much bandwidth to allocate

PARAMETERS

send_rate number
id string
Id of the object to send rate for

fusion.set_local_send_rate()

fusion.set_local_send_rate(send_rate,id)

Set the local send rate divisor for an object. A value of `1` means the object sends every tick (highest rate). A value of `16` means it sends every 16th tick (lowest rate). This is a client-side optimization -- the object still exists on all clients but consumes less bandwidth when you are not the active authority.

PARAMETERS

send_rate number
id string
Id of the object to send rate for

fusion.reset_send_rate()

fusion.reset_send_rate(id)

Reset the send rate of an object.

PARAMETERS

id string
Id of the object to reset send rate for

fusion.player_count()

fusion.player_count()

Get player count

PARAMETERS

None

RETURNS

number Number of players

fusion.is_master_client()

fusion.is_master_client()

Get if this client is the room's master

PARAMETERS

None

RETURNS

boolean True if this client is the room's master

fusion.get_rtt()

fusion.get_rtt()

Get round trip time

PARAMETERS

None

RETURNS

number Round trip time in seconds

fusion.network_time_diff()

fusion.network_time_diff()

Get raw offset between server time and local time. A positive value means the server clock is ahead of the local clock.

PARAMETERS

None

RETURNS

number Time diff

fusion.set_global_interest_key()

fusion.set_global_interest_key()

Set global visibility key for an object

PARAMETERS

None


fusion.set_area_interest_key()

fusion.set_area_interest_key()

Set area visibility key for an object

PARAMETERS

None


fusion.set_user_interest_key()

fusion.set_user_interest_key()

Set user visibility key for an object

PARAMETERS

None


fusion.set_area_keys()

fusion.set_area_keys(keys)

Set area visibility keys

PARAMETERS

keys table
Area keys to set. Stored as a table of key value pairs (area_key->send_rate)

fusion.add_user_key()

fusion.add_user_key()

Add a user visibility key

PARAMETERS

None


fusion.remove_user_key()

fusion.remove_user_key()

Remove a user visibility key from an object

PARAMETERS

None


Constants

OWNERMODE_TRANSACTION

OWNERMODE_TRANSACTION


OWNERMODE_PLAYERATTACHED

OWNERMODE_PLAYERATTACHED


OWNERMODE_DYNAMIC

OWNERMODE_DYNAMIC


OWNERMODE_MASTERCLIENT

OWNERMODE_MASTERCLIENT


OWNERMODE_GAMEGLOBAL

OWNERMODE_GAMEGLOBAL


STATE_DISCONNECTED

STATE_DISCONNECTED


STATE_CONNECTING

STATE_CONNECTING


STATE_CONNECTED

STATE_CONNECTED


STATE_JOININGROOM

STATE_JOININGROOM


STATE_INROOM

STATE_INROOM


STATE_LEAVINGROOM

STATE_LEAVINGROOM


STATE_DISCONNECTING

STATE_DISCONNECTING


DISCONNECT_CAUSE_NONE

DISCONNECT_CAUSE_NONE


DISCONNECT_CAUSE_DISCONNECTBYSERVERUSERLIMIT

DISCONNECT_CAUSE_DISCONNECTBYSERVERUSERLIMIT


DISCONNECT_CAUSE_EXCEPTIONONCONNECT

DISCONNECT_CAUSE_EXCEPTIONONCONNECT


DISCONNECT_CAUSE_DISCONNECTBYSERVER

DISCONNECT_CAUSE_DISCONNECTBYSERVER


DISCONNECT_CAUSE_DISCONNECTBYSERVERLOGIC

DISCONNECT_CAUSE_DISCONNECTBYSERVERLOGIC


DISCONNECT_CAUSE_TIMEOUTDISCONNECT

DISCONNECT_CAUSE_TIMEOUTDISCONNECT


DISCONNECT_CAUSE_EXCEPTION

DISCONNECT_CAUSE_EXCEPTION


DISCONNECT_CAUSE_INVALIDAUTHENTICATION

DISCONNECT_CAUSE_INVALIDAUTHENTICATION


DISCONNECT_CAUSE_MAXCCUREACHED

DISCONNECT_CAUSE_MAXCCUREACHED


DISCONNECT_CAUSE_INVALIDREGION

DISCONNECT_CAUSE_INVALIDREGION


DISCONNECT_CAUSE_OPERATIONNOTALLOWEDINCURRENTSTATE

DISCONNECT_CAUSE_OPERATIONNOTALLOWEDINCURRENTSTATE


DISCONNECT_CAUSE_CUSTOMAUTHENTICATIONFAILED

DISCONNECT_CAUSE_CUSTOMAUTHENTICATIONFAILED


DISCONNECT_CAUSE_CLIENTVERSIONTOOOLD

DISCONNECT_CAUSE_CLIENTVERSIONTOOOLD


DISCONNECT_CAUSE_CLIENTVERSIONINVALID

DISCONNECT_CAUSE_CLIENTVERSIONINVALID


DISCONNECT_CAUSE_DASHBOARDVERSIONINVALID

DISCONNECT_CAUSE_DASHBOARDVERSIONINVALID


DISCONNECT_CAUSE_AUTHENTICATIONTICKETEXPIRED

DISCONNECT_CAUSE_AUTHENTICATIONTICKETEXPIRED


DISCONNECT_CAUSE_DISCONNECTBYOPERATIONLIMIT

DISCONNECT_CAUSE_DISCONNECTBYOPERATIONLIMIT


EVENT_OBJECT_READY

EVENT_OBJECT_READY


EVENT_SUB_OBJECT_CREATED

EVENT_SUB_OBJECT_CREATED


EVENT_OBJECT_DESTROYED

EVENT_OBJECT_DESTROYED


EVENT_SUB_OBJECT_DESTROYED

EVENT_SUB_OBJECT_DESTROYED


EVENT_OBJECT_OWNER_CHANGED

EVENT_OBJECT_OWNER_CHANGED


EVENT_OBJECT_PREDICTION_OVERRIDE

EVENT_OBJECT_PREDICTION_OVERRIDE


EVENT_LOBBY_STATS

EVENT_LOBBY_STATS


EVENT_ROOM_JOINED

EVENT_ROOM_JOINED


EVENT_ROOM_LEFT

EVENT_ROOM_LEFT


EVENT_RPC

EVENT_RPC


EVENT_SCENE_CHANGE

EVENT_SCENE_CHANGE


EVENT_DESTROYED_MAP_ACTOR

EVENT_DESTROYED_MAP_ACTOR


EVENT_INTEREST_ENTER

EVENT_INTEREST_ENTER


EVENT_INTEREST_EXIT

EVENT_INTEREST_EXIT


EVENT_FORCED_DISCONNECT

EVENT_FORCED_DISCONNECT


EVENT_FUSION_START

EVENT_FUSION_START


EVENT_CONNECTED

EVENT_CONNECTED


EVENT_DISCONNECTED

EVENT_DISCONNECTED