Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
Fix errors and incorrect behavior when reconnecting
Browse files Browse the repository at this point in the history
  • Loading branch information
CombustibleLemonade committed Oct 3, 2020
1 parent 7cb93f1 commit 2cc72db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 8 additions & 4 deletions Game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var settingmap = {
"nickname": "set_nickname"
}

onready var peer = NetworkedMultiplayerENet.new()
var peer = NetworkedMultiplayerENet.new()
var local_player = null setget set_local_player

func set_local_player(player):
Expand Down Expand Up @@ -206,6 +206,9 @@ func free_client():
player_list_item.queue_free()

peer.close_connection()

get_tree().network_peer = null
local_player = null

func quit():
get_tree().quit()
Expand All @@ -222,7 +225,7 @@ func get_player_data():

return player_data

sync func check_players(player_data):
remote func check_players(player_data):
for player_name in player_data:
if not $Players.has_node(player_name):
var player = player_scene.instance()
Expand Down Expand Up @@ -255,6 +258,8 @@ func join_game():

var player_data = get_player_data()

set_network_master(1)

rpc("set_player_data", player_data)

func on_player_added(player):
Expand All @@ -281,8 +286,6 @@ master func set_player_data(player_data):
check_players(player_data)
var new_player_data = get_player_data()

print(new_player_data)

rpc("check_players", new_player_data)

func on_peer_disconnected(id):
Expand All @@ -291,6 +294,7 @@ func on_peer_disconnected(id):
rpc("remove_player", id)

func on_connection_established():
print("connection_established")
join_game()

func on_connection_failed():
Expand Down
4 changes: 0 additions & 4 deletions Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ onready var nickname = "guest" setget set_nickname
func set_health(value):
health = value
$HUD.updateHealth(value)
print(value)
$Billboard.rpc("set_health", value)
#$Billboard.set_health(value)

Expand Down Expand Up @@ -274,7 +273,6 @@ func reload():
weapon.reload()

func _input(event):

if is_dead:
return

Expand Down Expand Up @@ -339,8 +337,6 @@ func _ready():
# only show the debug label on local machine
if name != String(get_tree().get_network_unique_id()):
debug.hide()
print(get_tree().get_network_unique_id())
print(name)

# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
Expand Down

0 comments on commit 2cc72db

Please sign in to comment.