Jump to content

Welcome to the Forum!

The best place to exchange builds and ideas! Vote for the best ideas and suggestions here.

Join the Avorion Discord!

Connect with other passionate players and talk about the latest news.
Discord

DLC Avorion Into the Rift Out Now!

Now available on Steam!
Steam

API: Server():getPlayers() returns 0 players


Rinart73
 Share

Recommended Posts

0.18.2 - r12552, Windows 10 x64

 

I'm in the singleplayer game.

I add some code to the "data/scripts/server/server.lua" file, at the end of "update" function:

local players = {Server():getPlayers()}
print("#players = ", #players)
local playersOnline = {Server():getOnlinePlayers()}
print("#playersOnline = ", #playersOnline)

 

In the first case I get 0, in the second - 1. So I guess something is wrong with the "Server():getPlayers()" function?

Link to comment
Share on other sites

I'm *just* starting to fiddle around with scripting, and this is one of the first functions I was messing with in the console. I'm also Single Player Win 10 x64 on r12552.

 

In the console if I do

/run Server():getPlayers()

it returns a Player object.

/run Server():getPlayers().name

returns the correct name.

/run x = {Server():getPlayers()}, print(x)

prints nil.

 

I'm also just learning LUA - do the "{}" in variable declaration denote an array? Because it seems weird that that my first example returns a Player object, but surrounding it with curly braces to make it an array variable screws things up. 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...