52 lines
1.1 KiB
GDScript
52 lines
1.1 KiB
GDScript
extends Node
|
|
|
|
var peer = ENetMultiplayerPeer.new()
|
|
|
|
func _ready():
|
|
pass
|
|
|
|
|
|
func _process(delta):
|
|
pass
|
|
|
|
|
|
func _on_button_pressed():
|
|
get_tree().change_scene_to_file("res://scenes/mainmenu.tscn")
|
|
|
|
|
|
func _on_host_button_pressed():
|
|
var scene_trs =load("res://scenes/hostmenu.tscn")
|
|
var scene=scene_trs.instantiate()
|
|
add_child(scene)
|
|
|
|
|
|
func _on_join_button_pressed():
|
|
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
|
|
var result = peer.create_client(IPADD, intPORT)
|
|
var resultString = str(result)
|
|
$errorLabel.text = resultString
|
|
prints("Creating client result:", result)
|
|
if result != OK:
|
|
printerr("Did NOT connect to server")
|
|
$errorLabel.text = "Did NOT connect to server"
|
|
if result == OK:
|
|
print("Connected to server at IP ", IPADD, ":", intPORT, "!")
|
|
$errorLabel.text = "Connected to server!"
|
|
multiplayer.multiplayer_peer = peer
|
|
Global.multiplayerCurrent = true
|
|
|
|
|
|
|