project_teddy/scripts/multiplayer.gd

64 lines
1.6 KiB
GDScript3
Raw Normal View History

extends Node
2023-02-15 23:41:14 -07:00
var peer = ENetMultiplayerPeer.new()
2023-02-22 21:31:22 -07:00
var SCENE = "res://scenes/toyland.tscn"
func _ready():
$playerNameBox.text = Global.playerName
func _process(delta):
pass
func _on_button_pressed():
2023-02-24 23:49:49 -07:00
self.queue_free()
2023-02-09 13:10:25 -07:00
func _on_host_button_pressed():
var scene_trs =load("res://scenes/hostmenu.tscn")
var scene=scene_trs.instantiate()
2023-02-24 23:49:49 -07:00
get_parent().add_child(scene)
self.queue_free()
2023-02-09 13:10:25 -07:00
func _on_join_button_pressed():
2023-02-28 11:48:41 -07:00
peer.close()
2023-02-09 13:10:25 -07:00
var IPADD
var PORT
var intPORT
if $ipBox.text:
IPADD = $ipBox.text
else:
$errorLabel.text = "ERROR: NO IP SPECIFIED"
return
if $portBox.text:
PORT = $portBox.text
intPORT = int(PORT)
else:
$errorLabel.text = "ERROR: NO PORT SPECIFIED"
return
2023-03-09 13:26:09 -07:00
if Global.playerName == "":
$errorLabel.text = "NAME CAN'T BE BLANK"
return
2023-02-09 13:10:25 -07:00
var result = peer.create_client(IPADD, intPORT)
var resultString = str(result)
$errorLabel.text = resultString
prints("Creating client result:", result)
if result != OK:
2023-02-28 11:48:41 -07:00
printerr("Failed to create client object, please report to Paul/Techwizz")
$errorLabel.text = "Failed to create client object, please report to Paul/Techwizz"
2023-02-09 13:10:25 -07:00
if result == OK:
2023-02-21 13:34:05 -07:00
print("Connecting to server at IP ", IPADD, ":", intPORT, "...")
$errorLabel.text = "Connecting to server..."
2023-02-15 23:41:14 -07:00
multiplayer.multiplayer_peer = peer
2023-02-28 11:48:41 -07:00
await get_tree().create_timer(5).timeout
printerr("FAILED TO CONNECT, CHECK INFO THEN TRY AGAIN")
$errorLabel.text = "FAILED TO CONNECT, CHECK INFO THEN TRY AGAIN"
2023-02-14 13:29:43 -07:00
func _on_player_name_box_text_changed(new_text):
Global.playerName = new_text
SettingsFile.save_data(Global.mouseSensitivity, Global.playerName)