Godot Version
4.5
Question
So im making a game and both the players are id 1 for some reason im using the gdsync plugin i cansend scripts like the one where it creates and joins lobby or spawns player both player id are 1 so i cant really make anything like vc
With absolutely no code shown or even any screenshots / examples, it’s very likely that nobody can help you.
this is my current one for lobby creating and joining
extends Control
@onready var create := $CreateGameButton
@onready var join := $JoinGameButton
@onready var input := $LobbyCodeInput
@onready var connecting := $Connecting
@onready var playername := $PlayerName
var is_host := false
func _ready() -> void:
create.pressed.connect(_on_create_game_button_pressed)
join.pressed.connect(_on_join_game_button_pressed)
GDSync.connection_failed.connect(connection_failed)
GDSync.lobby_created.connect(lobby_created)
GDSync.lobby_creation_failed.connect(lobby_creation_failed)
GDSync.lobby_joined.connect(lobby_joined)
GDSync.lobby_join_failed.connect(lobby_join_failed)
GDSync.start_multiplayer()
func _on_create_game_button_pressed() -> void:
if playername.text.strip_edges() == "" or playername.text.strip_edges().length() > 20:
connecting.get_node("Label").text = "Enter a valid username"
connecting.visible = true
return
is_host = true
var code = str(100000 + randi() % 900000)
GDSync.lobby_create(code)
connecting.visible = true
await get_tree().create_timer(1.0).timeout
if connecting.visible:
connecting.get_node("Label").text = "Please try again"
await get_tree().create_timer(1.0).timeout
if connecting.visible:
connecting.visible = false
connecting.get_node("Label").text = "Connecting..."
func _on_join_game_button_pressed() -> void:
if playername.text.strip_edges() == "" or playername.text.strip_edges().length() > 20:
connecting.get_node("Label").text = "Enter a valid username"
connecting.visible = true
return
var code = input.text.strip_edges()
if code == "":
connecting.get_node("Label").text = "Enter a valid lobby code"
connecting.visible = true
return
is_host = false
GDSync.lobby_join(code, playername.text.strip_edges())
connecting.visible = true
await get_tree().create_timer(1.0).timeout
if connecting.visible:
connecting.get_node("Label").text = "Please try again"
await get_tree().create_timer(1.0).timeout
if connecting.visible:
connecting.visible = false
connecting.get_node("Label").text = "Connecting..."
func connection_failed(error: int) -> void:
connecting.visible = false
match error:
ENUMS.CONNECTION_FAILED.INVALID_PUBLIC_KEY:
show_error("Invalid key")
ENUMS.CONNECTION_FAILED.TIMEOUT:
show_error("Connection timed out")
func lobby_created(lobby_name: String) -> void:
if is_host:
GDSync.lobby_join(lobby_name, playername.text.strip_edges())
print("Lobby created:", lobby_name)
connecting.visible = false
func lobby_creation_failed(_lobby_name: String, error: int) -> void:
if error == ENUMS.LOBBY_CREATION_ERROR.LOBBY_ALREADY_EXISTS:
print("Lobby already exists")
connecting.visible = false
func lobby_joined(lobby_name: String) -> void:
print("Joined lobby", lobby_name)
LobbyManager.lobby_name = lobby_name
LobbyManager.username = playername.text.strip_edges()
GDSync.player_set_username(LobbyManager.username)
connecting.visible = false
get_tree().change_scene_to_file("res://Game.tscn")
func lobby_join_failed(lobby_name: String, _error: int) -> void:
show_error("Failed to join lobby " + lobby_name)
connecting.visible = false
func show_error(msg: String) -> void:
print("ERROR:", msg)