defold/extension-photon-fusion/fusion
Functions and constants for interacting with Photon Fusion
- GitHub: defold/extension-photon-fusion — pinned to
1.0(released while Defold 1.13.1 was current)- Pick a release from defold/extension-photon-fusion releases and add its Source code (zip) URL (or a packaged
.zipasset, if the library ships one) togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as fusion from "fusion"
- Pick a release from defold/extension-photon-fusion releases and add its Source code (zip) URL (or a packaged
Functions
fusion.init(app_id: string, app_version: string, protocol?: string)fusion.init_from_settings()fusion.connect(user?: string)fusion.disconnect()fusion.reconnect()fusion.start()fusion.stop()fusion.get_state(): numberfusion.get_disconnect_cause(): numberfusion.join_or_create_room_random(create_room_options?: table, matchmaking_options?: table)fusion.join_room_random(matchmaking_options?: table)fusion.join_room(room_name: string, join_room_options?: table)fusion.join_or_create_room(room_name: string, create_room_options?: table, join_room_options?: table)fusion.create_room(room_name: string, create_room_options?: table)fusion.leave_room(will_come_back?: boolean, send_auth_cookie?: boolean)fusion.is_connected(): booleanfusion.is_running(): booleanfusion.is_started(): booleanfusion.is_in_room(): booleanfusion.enable_debug(enable: boolean)fusion.create_map_object(map: number, owner_mode: number, options: table, id?: string)fusion.spawn(factory_url: string, position: vector3 | undefined, rotation: quat | undefined, map: number, owner_mode: number, options: table): hashfusion.despawn(id?: string)fusion.create_object(factory_url: string, map: number, owner_mode: number, options: table, id?: string)fusion.destroy_object(id?: string)fusion.map_add(data: string): numberfusion.map_change(data: string): numberfusion.map_remove(map: number)fusion.map_is_valid(map: number): booleanfusion.send_rpc(target_player: number, target_object: hash, event: hash, data?: table): booleanfusion.subscribe_rpc(rpc_event: hash, id?: hash)fusion.unsubscribe_rpc(rpc_event: hash, id?: hash)fusion.on_event(listener: function)fusion.get_local_player_id(): numberfusion.get_owner_id(id?: string): numberfusion.has_authority(id?: string): booleanfusion.has_owner(id?: string): booleanfusion.want_authority(claim_ownership: boolean, id?: string)fusion.clear_owner_cooldown(id?: string)fusion.respond_to_ownership_request(object: string, requester: number, granted: boolean)fusion.set_room_send_rate(send_rate: number, id?: string)fusion.set_local_send_rate(send_rate: number, id?: string)fusion.reset_room_send_rate(id?: string)fusion.player_count(): numberfusion.is_master_client(): booleanfusion.get_rtt(): numberfusion.get_network_time(): numberfusion.network_time_diff(): numberfusion.set_global_interest_key(id: hash)fusion.set_area_interest_key(key: hash, id: hash)fusion.set_user_interest_key(key: hash, id: hash)fusion.set_area_keys(keys: table)fusion.add_user_key(key: hash)fusion.remove_user_key(key: hash)
fusion.init(app_id: string, app_version: string, protocol?: string)
Initialize Fusion.
Parameters
app_id:stringapp_version:stringprotocol?:string— One of wss, ws, tcp or udp
fusion.init_from_settings()
Initialize Fusion from game.project settings.
fusion.connect(user?: string)
Connect Fusion.
Parameters
user?:string
fusion.disconnect()
Disonnect Fusion.
fusion.reconnect()
Reconnect Fusion.
fusion.start()
Start Fusion sync.
fusion.stop()
Stop Fusion sync.
fusion.get_state(): number
Get connection state.
Returns
state:number— The connection state
fusion.get_disconnect_cause(): number
Get disconnect cause.
Returns
cause:number— The disconnect cause
fusion.join_or_create_room_random(create_room_options?: table, matchmaking_options?: table)
Join or create random room.
Parameters
create_room_options?:tablematchmaking_options?:table
fusion.join_room_random(matchmaking_options?: table)
Join random room.
Parameters
matchmaking_options?:table
fusion.join_room(room_name: string, join_room_options?: table)
Join room.
Parameters
room_name:stringjoin_room_options?:table
fusion.join_or_create_room(room_name: string, create_room_options?: table, join_room_options?: table)
Join or create room.
Parameters
room_name:stringcreate_room_options?:tablejoin_room_options?:table
fusion.create_room(room_name: string, create_room_options?: table)
Create room.
Parameters
room_name:stringcreate_room_options?:table
fusion.leave_room(will_come_back?: boolean, send_auth_cookie?: boolean)
Leave room.
Parameters
will_come_back?:booleansend_auth_cookie?:boolean
fusion.is_connected(): boolean
Check if Fusion is connected.
Returns
connected:boolean
fusion.is_running(): boolean
Check if Fusion has config and is connected.
Returns
running:boolean
fusion.is_started(): boolean
Check if Fusion is started. Fusion is considered started after a call to.
fusion.start() has received a EventOnFusionStart event.
Returns
started:boolean
fusion.is_in_room(): boolean
Check if Fusion is in a room.
Returns
in_room:boolean
fusion.enable_debug(enable: boolean)
Enable/disable debugging.
Parameters
enable:boolean
fusion.create_map_object(map: number, owner_mode: number, options: table, id?: string)
Create a map object.
Parameters
map:numberowner_mode:numberoptions:table— Table withpropertiesandreplication_modefields. The properties field should be a id,property map with script ids and properties to sync. Replication mode should be one of the establishedREPLICATION_MODEconstants.id?:string
fusion.spawn(factory_url: string, position: vector3 | undefined, rotation: quat | undefined, map: number, owner_mode: number, options: table): hash
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:stringposition:vector3 | undefined— Initial position of created game objectrotation:quat | undefined— Initial rotation of created game objectmap:number— The map to which this object belongsowner_mode:number— Owner mode of spawned objectoptions:table— Table withpropertiesandreplication_modefields. The properties field should be a id,property map with script ids and properties to sync. Replication mode should be one of the establishedREPLICATION_MODEconstants.
Returns
id:hash— Id of the spawned game object
fusion.despawn(id?: string)
Destroy a networked object.
Parameters
id?:string
fusion.create_object(factory_url: string, map: number, owner_mode: number, options: table, id?: string)
Create an object.
Parameters
factory_url:stringmap:numberowner_mode:numberoptions:tableid?:string
fusion.destroy_object(id?: string)
Destroy a previously created object.
Parameters
id?:string
fusion.map_add(data: string): number
Add map.
Parameters
data:string
Returns
id:number— Map id
fusion.map_change(data: string): number
Change map.
Parameters
data:string
Returns
id:number— Map id
fusion.map_remove(map: number)
Remove map.
Parameters
map:number— Map id
fusion.map_is_valid(map: number): boolean
Check if map is valid.
Parameters
map:number— Map id
Returns
valid:boolean— True if valid
fusion.send_rpc(target_player: number, target_object: hash, event: hash, data?: table): boolean
Send an RPC event. Events can be sent to a specific player or all players, and. To a specific object or to all subscribers.
Parameters
target_player:number— 0 = all, specific PlayerId = targetedtarget_object:hash— Id of game object, nil for broadcastevent:hashdata?:table
Returns
ok:boolean
fusion.subscribe_rpc(rpc_event: hash, id?: hash)
Subscribe to RPC broadcast event. The events will be delivered as messages.
Parameters
rpc_event:hash— Event to subscribe toid?:hash— Subscriber id
fusion.unsubscribe_rpc(rpc_event: hash, id?: hash)
Unsubscribe from a subscribed RPC event.
Parameters
rpc_event:hash— Event to unsubscribe toid?:hash— Which object should unsubscribe
fusion.on_event(listener: function)
Set event listener.
Parameters
listener:function
fusion.get_local_player_id(): number
Get the player id of the local client
Returns
id:number— The player id of the local client
fusion.get_owner_id(id?: string): number
Get the player id of the current owner of an object
Parameters
id?:string— Id of the object to get the owner for
Returns
owner_id:number— The player id of the object's owner
fusion.has_authority(id?: string): boolean
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
authority:boolean— Returns true if the client has authority
fusion.has_owner(id?: string): boolean
Check if an object has an owner
Parameters
id?:string— Id of the object
Returns
has_owner:boolean— True if the object has an owner
fusion.want_authority(claim_ownership: boolean, id?: string)
Signal desire for the local client to own an object
Parameters
claim_ownership:booleanid?:string— Id of the object to own
fusion.clear_owner_cooldown(id?: string)
Explicitly clear the ownership cooldown
Parameters
id?:string— Id of the object to clear cooldown for
fusion.respond_to_ownership_request(object: string, requester: number, granted: boolean)
Respond to a received ownership request
Parameters
object:string— Id of the objectrequester:number— Requesting player idgranted:boolean— True if the request is granted
fusion.set_room_send_rate(send_rate: number, id?: string)
Set the send rate of an object. This decided how much bandwidth to allocate
Parameters
send_rate:numberid?:string— Id of the object to send rate for
fusion.set_local_send_rate(send_rate: number, id?: string)
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:numberid?:string— Id of the object to send rate for
fusion.reset_room_send_rate(id?: string)
Reset the send rate of an object.
Parameters
id?:string— Id of the object to reset send rate for
fusion.player_count(): number
Get player count
Returns
count:number— Number of players
fusion.is_master_client(): boolean
Get if this client is the room's master
Returns
master:boolean— True if this client is the room's master
fusion.get_rtt(): number
Get round trip time
Returns
rtt:number— Round trip time in seconds
fusion.get_network_time(): number
Get the network time
Returns
time:number— Network time
fusion.network_time_diff(): number
Get raw offset between server time and local time. A positive value means the server clock is ahead of the local clock.
Returns
diff:number— Time diff
fusion.set_global_interest_key(id: hash)
Set global visibility key for an object
Parameters
id:hash— Object to set global visibility key for
fusion.set_area_interest_key(key: hash, id: hash)
Set area visibility key for an object
Parameters
key:hash— Area keyid:hash— Object to set area visibility key for
fusion.set_user_interest_key(key: hash, id: hash)
Set user visibility key for an object
Parameters
key:hash— User keyid:hash— Object to set user visibility key for
fusion.set_area_keys(keys: table)
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(key: hash)
Add a user visibility key to the set of local interest keys.
Parameters
key:hash— User key to add
fusion.remove_user_key(key: hash)
Remove a user visibility key from the set of local interest keys.
Parameters
key:hash— User key to remove
Constants
fusion.OWNERMODE_TRANSACTION
OWNERMODE_TRANSACTION
fusion.OWNERMODE_PLAYERATTACHED
OWNERMODE_PLAYERATTACHED
fusion.OWNERMODE_DYNAMIC
OWNERMODE_DYNAMIC
fusion.OWNERMODE_MASTERCLIENT
OWNERMODE_MASTERCLIENT
fusion.OWNERMODE_GAMEGLOBAL
OWNERMODE_GAMEGLOBAL
fusion.STATE_DISCONNECTED
STATE_DISCONNECTED
fusion.STATE_CONNECTING
STATE_CONNECTING
fusion.STATE_CONNECTED
STATE_CONNECTED
fusion.STATE_JOININGROOM
STATE_JOININGROOM
fusion.STATE_INROOM
STATE_INROOM
fusion.STATE_LEAVINGROOM
STATE_LEAVINGROOM
fusion.STATE_DISCONNECTING
STATE_DISCONNECTING
fusion.DISCONNECT_CAUSE_NONE
DISCONNECT_CAUSE_NONE
fusion.DISCONNECT_CAUSE_DISCONNECTBYSERVERUSERLIMIT
DISCONNECT_CAUSE_DISCONNECTBYSERVERUSERLIMIT
fusion.DISCONNECT_CAUSE_EXCEPTIONONCONNECT
DISCONNECT_CAUSE_EXCEPTIONONCONNECT
fusion.DISCONNECT_CAUSE_DISCONNECTBYSERVER
DISCONNECT_CAUSE_DISCONNECTBYSERVER
fusion.DISCONNECT_CAUSE_DISCONNECTBYSERVERLOGIC
DISCONNECT_CAUSE_DISCONNECTBYSERVERLOGIC
fusion.DISCONNECT_CAUSE_TIMEOUTDISCONNECT
DISCONNECT_CAUSE_TIMEOUTDISCONNECT
fusion.DISCONNECT_CAUSE_EXCEPTION
DISCONNECT_CAUSE_EXCEPTION
fusion.DISCONNECT_CAUSE_INVALIDAUTHENTICATION
DISCONNECT_CAUSE_INVALIDAUTHENTICATION
fusion.DISCONNECT_CAUSE_MAXCCUREACHED
DISCONNECT_CAUSE_MAXCCUREACHED
fusion.DISCONNECT_CAUSE_INVALIDREGION
DISCONNECT_CAUSE_INVALIDREGION
fusion.DISCONNECT_CAUSE_OPERATIONNOTALLOWEDINCURRENTSTATE
DISCONNECT_CAUSE_OPERATIONNOTALLOWEDINCURRENTSTATE
fusion.DISCONNECT_CAUSE_CUSTOMAUTHENTICATIONFAILED
DISCONNECT_CAUSE_CUSTOMAUTHENTICATIONFAILED
fusion.DISCONNECT_CAUSE_CLIENTVERSIONTOOOLD
DISCONNECT_CAUSE_CLIENTVERSIONTOOOLD
fusion.DISCONNECT_CAUSE_CLIENTVERSIONINVALID
DISCONNECT_CAUSE_CLIENTVERSIONINVALID
fusion.DISCONNECT_CAUSE_DASHBOARDVERSIONINVALID
DISCONNECT_CAUSE_DASHBOARDVERSIONINVALID
fusion.DISCONNECT_CAUSE_AUTHENTICATIONTICKETEXPIRED
DISCONNECT_CAUSE_AUTHENTICATIONTICKETEXPIRED
fusion.DISCONNECT_CAUSE_DISCONNECTBYOPERATIONLIMIT
DISCONNECT_CAUSE_DISCONNECTBYOPERATIONLIMIT
fusion.MASTER_CLIENT_PLAYER_ID
MASTER_CLIENT_PLAYER_ID
fusion.PLUGIN_PLAYER_ID
PLUGIN_PLAYER_ID
fusion.OBJECT_OWNER_PLAYER_ID
OBJECT_OWNER_PLAYER_ID
fusion.REPLICATION_MODE_NONE
REPLICATION_MODE_NONE
fusion.REPLICATION_MODE_AUTO
REPLICATION_MODE_AUTO
fusion.FORCED_DISCONNECT_REASON_GENERIC
FORCED_DISCONNECT_REASON_GENERIC
fusion.FORCED_DISCONNECT_REASON_PROTOCOLINCOMPATIBLE
FORCED_DISCONNECT_REASON_PROTOCOLINCOMPATIBLE
fusion.FORCED_DISCONNECT_REASON_ROOMVERSIONMISMATCH
FORCED_DISCONNECT_REASON_ROOMVERSIONMISMATCH
fusion.EVENT_OBJECT_READY
EVENT_OBJECT_READY
fusion.EVENT_SUB_OBJECT_CREATED
EVENT_SUB_OBJECT_CREATED
fusion.EVENT_OBJECT_DESTROYED
EVENT_OBJECT_DESTROYED
fusion.EVENT_SUB_OBJECT_DESTROYED
EVENT_SUB_OBJECT_DESTROYED
fusion.EVENT_OBJECT_FORCE_ALIVE
EVENT_OBJECT_FORCE_ALIVE
fusion.EVENT_SUB_OBJECT_FORCE_ALIVE
EVENT_SUB_OBJECT_FORCE_ALIVE
fusion.EVENT_OBJECT_OWNER_CHANGED
EVENT_OBJECT_OWNER_CHANGED
fusion.EVENT_PREDICTION_OVERRIDE
EVENT_PREDICTION_OVERRIDE
fusion.EVENT_LOBBY_STATS
EVENT_LOBBY_STATS
fusion.EVENT_ROOM_JOINED
EVENT_ROOM_JOINED
fusion.EVENT_ROOM_LEFT
EVENT_ROOM_LEFT
fusion.EVENT_RPC
EVENT_RPC
fusion.EVENT_MAP_CHANGE
EVENT_MAP_CHANGE
fusion.EVENT_DESTROYED_MAP_ACTOR
EVENT_DESTROYED_MAP_ACTOR
fusion.EVENT_INTEREST_ENTER
EVENT_INTEREST_ENTER
fusion.EVENT_INTEREST_EXIT
EVENT_INTEREST_EXIT
fusion.EVENT_FORCED_DISCONNECT
EVENT_FORCED_DISCONNECT
fusion.EVENT_FUSION_START
EVENT_FUSION_START
fusion.EVENT_CONNECTED
EVENT_CONNECTED
fusion.EVENT_DISCONNECTED
EVENT_DISCONNECTED
fusion.EVENT_DEFOLD_LOG_EVENT
EVENT_DEFOLD_LOG_EVENT