Hi!
I’m implementing a match lobby system (for configuring match settings) before the match start. I’m trying to list all players in a match, but the problem is that only the first player receives all the presences:
I also tried to put a button to manually update the match players, but apparently the match object isn’t getting synced.
func update_players_list() -> void:
item_list_players.clear()
if GlobalData.match_ == null:
return
var presences: Array = [GlobalData.match_.self_user]
presences.append_array(GlobalData.match_.presences)
for presence in presences:
item_list_players.add_item(
presence.username, null, false
)
func _on_received_match_presence(match_presence: NakamaRTAPI.MatchPresenceEvent) -> void:
print("Received Match Presence: ", match_presence) # DEBUG
update_players_list()
Both match and match_ticket objects are declared in a singleton ‘global_data.gd’:
# global_data.gd
@onready var match_: NakamaRTAPI.Match = null
@onready var matchmaker_ticket: NakamaRTAPI.MatchmakerTicket = null
Another implementation (with the same result) was putting an array at the singleton, then updating every player presence event:
func update_players_list() -> void:
item_list_players.clear()
for presence in GlobalData.match_presences:
item_list_players.add_item(presence.username, null, false)
func _on_received_match_presence(match_presence: NakamaRTAPI.MatchPresenceEvent) -> void:
print("Received Match Presence: ", match_presence) # DEBUG
for presence in match_presence.joins:
if not presence in GlobalData.match_presences:
GlobalData.match_presences.append(presence)
for presence in match_presence.leaves:
if presence in GlobalData.match_presences:
GlobalData.match_presences.erase(presence)
update_players_list()
# global_data.gd
@onready var match_presences: Array[NakamaRTAPI.UserPresence] = []
How can I fix my code? Is there a better way to do that?