Version: stable
fusion.init(app_id,app_version,protocol)
Initialize Fusion.
PARAMETERS
app_id |
string |
|
app_version |
string |
|
protocol |
string |
One of wss, ws, tcp or udp |
fusion.init_from_settings()
Initialize Fusion from game.project settings.
PARAMETERS
None
fusion.connect(user,auth)
Connect Fusion.
PARAMETERS
user |
string |
Player display name, separate from the authentication user id. |
auth |
table |
Authentication options. Omit or pass nil for anonymous authentication. Optional fields: `type` (a `fusion.AUTH_TYPE_*` constant, defaults to `AUTH_TYPE_NONE`), `user_id` (string), `parameters` (URL-encoded query string without a leading `?`), and `data` (POST data: a string or a table with string keys and string, number or boolean values). An empty table is an empty property map. Nested tables are not supported. Configure the provider and disable anonymous access in the Photon dashboard to require authentication. |
fusion.get_state()
Get connection state.
PARAMETERS
None
RETURNS
number |
The connection state |
fusion.get_disconnect_cause()
Get disconnect cause.
PARAMETERS
None
RETURNS
number |
The disconnect cause |
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(matchmaking_options)
Join random room.
PARAMETERS
matchmaking_options |
table |
fusion.join_room(room_name,join_room_options)
Join room.
PARAMETERS
room_name |
string |
|
join_room_options |
table |
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(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()
Check if Fusion is connected.
PARAMETERS
None
RETURNS
boolean |
fusion.is_running()
Check if Fusion has config and is connected.
PARAMETERS
None
RETURNS
boolean |
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.enable_debug(enable)
Enable/disable debugging.
PARAMETERS
enable |
boolean |
fusion.create_map_object(map,owner_mode,options,id)
Create a map object.
PARAMETERS
map |
number |
|
owner_mode |
number |
|
options |
table |
Table with `properties` and `replication_mode` fields. The properties field should be a id,property map with script ids and properties to sync. Replication mode should be one of the established `REPLICATION_MODE` constants. |
id |
string |
fusion.spawn(factory_url,position,rotation,map,owner_mode,options)
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 |
map |
number |
The map to which this object belongs |
owner_mode |
number |
Owner mode of spawned object |
options |
table |
Table with `properties` and `replication_mode` fields. The properties field should be a id,property map with script ids and properties to sync. Replication mode should be one of the established `REPLICATION_MODE` constants. |
RETURNS
hash |
Id of the spawned game object |
fusion.create_object(factory_url,map,owner_mode,options,id)
Create an object.
PARAMETERS
factory_url |
string |
|
map |
number |
|
owner_mode |
number |
|
options |
table |
|
id |
string |
fusion.destroy_object(id)
Destroy a previously created object.
PARAMETERS
id |
string |
fusion.map_change(data)
Change map.
PARAMETERS
data |
string |
RETURNS
number |
Map id |
fusion.map_is_valid(map)
Check if map is valid.
PARAMETERS
map |
number |
Map id |
RETURNS
boolean |
True if valid |
fusion.send_rpc(target_player,target_object,event,data)
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 = targeted |
target_object |
hash |
Id of game object, nil for broadcast |
event |
hash |
|
data |
table |
RETURNS
boolean |
fusion.subscribe_rpc(rpc_event,id)
Subscribe to RPC broadcast event. The events will be delivered as messages.
PARAMETERS
rpc_event |
hash |
Event to subscribe to |
id |
hash |
Subscriber id |
fusion.unsubscribe_rpc(rpc_event,id)
Unsubscribe from a subscribed RPC event.
PARAMETERS
rpc_event |
hash |
Event to unsubscribe to |
id |
hash |
Which object should unsubscribe |
fusion.get_local_player_id()
Get the player id of the local client
PARAMETERS
None
RETURNS
number |
The player id of the local client |
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 |
The player id of the object's owner |
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(id)
Check if an object has an owner
PARAMETERS
id |
string |
Id of the object |
RETURNS
boolean |
True if the object has an owner |
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(id)
Explicitly clear the ownership cooldown
PARAMETERS
id |
string |
Id of the object to clear cooldown for |
fusion.respond_to_ownership_request(object,requester,granted)
Respond to a received ownership request
PARAMETERS
object |
string |
Id of the object |
requester |
number |
Requesting player id |
granted |
boolean |
True if the request is granted |
fusion.set_room_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(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_room_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()
Get player count
PARAMETERS
None
RETURNS
number |
Number of players |
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()
Get round trip time
PARAMETERS
None
RETURNS
number |
Round trip time in seconds |
fusion.get_network_time()
Get the network time
PARAMETERS
None
RETURNS
number |
Network time |
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(id)
Set global visibility key for an object
PARAMETERS
id |
hash |
Object to set global visibility key for |
fusion.set_area_interest_key(key,id)
Set area visibility key for an object
PARAMETERS
key |
hash |
Area key |
id |
hash |
Object to set area visibility key for |
fusion.set_user_interest_key(key,id)
Set user visibility key for an object
PARAMETERS
key |
hash |
User key |
id |
hash |
Object to set user visibility key for |
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(key)
Add a user visibility key to the set of local interest keys.
PARAMETERS
key |
hash |
User key to add |
fusion.remove_user_key(key)
Remove a user visibility key from the set of local interest keys.
PARAMETERS
key |
hash |
User key to remove |
DISCONNECT_CAUSE_OPERATIONNOTALLOWEDINCURRENTSTATE