0 votes

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:

extends Node

var players = []

func _init():
    var host = NetworkedMultiplayerENet.new()
    host.create_server(9000, 64)

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

MBP:game dd$ /Applications/Godot3Bin -s ./server.gd 
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 :)

in Engine by (56 points)

2 Answers

0 votes

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.

by (427 points)
+1 vote

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

by (16 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.