[0.16.51] Only able to run command in multiplayer?

Place to get help with not working mods / modding interface.
Post Reply
AreYouScared
Long Handed Inserter
Long Handed Inserter
Posts: 87
Joined: Thu Mar 23, 2017 3:32 am
Contact:

[0.16.51] Only able to run command in multiplayer?

Post by AreYouScared »

I'm attempting to fun the following command to get the play time for all players on 43 maps, sadly one at a time.

Command:

Code: Select all

/command 
game.write_file("TimeOnline/timeOnline.txt","",false,0)  
for _,player in pairs(game.players) do    
local tick = player.online_time    
local pre_seconds = tick/60    
local pre_minutes = pre_seconds/60    
local pre_hours = pre_minutes/60    
local days = math.floor((pre_hours)/24)    
local hours = math.floor(pre_hours - 24*days)    
local minutes = math.floor((pre_minutes - 60*(hours + 24*days)))    
local seconds = math.floor(((pre_seconds - 60*minutes)-60*(60*(hours + 24*days))))    
local returnString = "name: "..player.name.." has played on the server for "..days.." days "..hours.." hours "..minutes.." minutes "..seconds.." seconds"        game.write_file("TimeOnline/timeOnline.txt",returnString.."\n",true,0)  end
Issue: When a map is loaded in single player the command shows its ran as a command but doesn't export the file like it should, Load the map on a headless or 'Host saved game'
Image

Bilka
Factorio Staff
Factorio Staff
Posts: 3139
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: [0.16.51] Only able to run command in multiplayer?

Post by Bilka »

game.write_file("TimeOnline/timeOnline.txt","",false,0)
game.write_file("TimeOnline/timeOnline.txt",returnString.."\n",true,0)
You are writing for player 0, the headless server (http://lua-api.factorio.com/latest/LuaG ... write_file). Remove the parameter and it will also write to file in singleplayer.

Moved to modding help.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Modding help”