Author Topic: API: Server():getPlayers() returns 0 players  (Read 88 times)

Rinart73

  • Full Member
  • ***
  • Status:
    Offline
    Posts:
    239
  • Discord: Rinart73#7304
    • View Profile
on: August 13, 2018, 02:20:48 AM
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:
Code: [Select]
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?



Sandworm

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    16
    • View Profile
on: August 19, 2018, 11:08:37 PM
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
Code: [Select]
/run Server():getPlayers()it returns a Player object.
Code: [Select]
/run Server():getPlayers().namereturns the correct name.
Code: [Select]
/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.