MultiplayerAPI is_network_server Fails Silently
Removes the error message when the network peer is not valid and returns false instead.
This makes it simpler to make games that are both on/offline by replacing server checks of
'''
if is_instance_valid(get_tree().network_peer) and get_tree().is_network_server():
# Do server things
'''
with
'''
if get_tree().is_network_server():
# Do server things
'''
Requires no changes to the docs because both the MultiplayerAPI and SceneTree docs don't mention the error.
(cherry picked from commit 74379b15ff
)
This commit is contained in:
parent
6026de80e7
commit
f218e9e929
1 changed files with 1 additions and 3 deletions
|
@ -796,9 +796,7 @@ int MultiplayerAPI::get_network_unique_id() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MultiplayerAPI::is_network_server() const {
|
bool MultiplayerAPI::is_network_server() const {
|
||||||
// XXX Maybe fail silently? Maybe should actually return true to make development of both local and online multiplayer easier?
|
return network_peer.is_valid() && network_peer->is_server();
|
||||||
ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), false, "No network peer is assigned. I can't be a server.");
|
|
||||||
return network_peer->is_server();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiplayerAPI::set_refuse_new_network_connections(bool p_refuse) {
|
void MultiplayerAPI::set_refuse_new_network_connections(bool p_refuse) {
|
||||||
|
|
Loading…
Reference in a new issue