Run multiplayer server script from command line

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By desik
:warning: Old Version Published before Godot 3 was released.

Hi,
I’ve started to learn about new high level multiplayer in Godot.
I wanted to create simple server which will log all connected clients.

I followed some part of tutorial:

I wanted to start server as separate process - just for server, so I wanted to run such script from command line:

    #server.gd
extends Node

var players = []

func _init():
	var host = NetworkedMultiplayerENet.new()
	host.create_server(9000, 64)
	get_tree().set_network_peer(host)
	print('Test')

but because it doesn’t inherit from MainLoop or SceneTree, I get error:

MBP:game dd$ /Applications/Godot3Bin -s ./server.gd 
arguments
0: /Applications/Godot3Bin
1: -s
2: ./server.gd
Current path: /Users/dd/Dropbox/Dev/game
OpenGL ES 3.0 Renderer: Intel(R) Iris(TM) Graphics 6100
GLES3: max ubo light: 409
GLES3: max ubo reflections: 455, ubo size: 144
Registered interface Native mobile
ERROR: start: Can't load script './server.gd', it does not inherit from a MainLoop type
   At: main/main.cpp:1273.

When I change the class I inherit from to SceneTree for example, then I get:

SCRIPT ERROR: _init: Invalid call. Nonexistent function 'get_tree' in base 'SceneTree (server.gd)'.

Any suggestions how can I run command line server code?
FYI I use MacOS
Thanks guys :slight_smile:

:bust_in_silhouette: Reply From: hungrymonkey

If the directory have a godot.project

you can use something like

godot/bin/godot.tools.???. --path /path/to/godot.project.dir/

I have to warn you. if run the project on another os, different return characters between os can sometimes cause the program to not work which you have to go to the godot editors and resave the file to fix.

:bust_in_silhouette: Reply From: Adwaith H Sivam

You don’t need to use get_tree(). Your script is in itself a SceneTree because you are extending from it. So just use set_network_peer(host) directly