on_player_created, game.players and game.get_player

This subforum contains all the issues which we already resolved.
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1525
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

on_player_created, game.players and game.get_player

Post by binbinhfr »

Hi, I had a long time hunting this problem with my mod, and here is what I found.

Let say I create a map in SP with player binbin2, in order to use it in MP.

Then I run it on a headless server, whose name is binbin0
Then I connect with a different normal player called binbin1.

If I have this simple mod :

Code: Select all

script.on_event(defines.events.on_player_created,
	function(event)
		local player1 = game.players[event.player_index]
		local player2 = game.get_player(event.player_index)
		player1.print( "on_player_created " .. player1.name .. "=" .. tostring(player1.connected) .. " " .. player2.name .. "=" .. tostring(player2.connected) )
		player2.print( "on_player_created " .. player1.name .. "=" .. tostring(player1.connected) .. " " .. player2.name .. "=" .. tostring(player2.connected) )
	end
)

the first print gives nothing on console.
the second print gives :
Binbin2 = false Binbin1 = true

player1 and player2 are not the same !
So game.players refers to the old connected player that is offline...
But they should have disctinct index, no ?

Then if I connect the MP game with binbin2, I have a normal reconnexion, with no player_created.

I had such a long time finding this one ! ;)
My mods on the Factorio Mod Portal :geek:
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1525
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: on_player_created, game.players and game.get_player

Post by binbinhfr »

ooops edited, I did not copy the right code, please reload it.
My mods on the Factorio Mod Portal :geek:
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5410
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: on_player_created, game.players and game.get_player

Post by Klonan »

Thanks for the report,

In 0.13 the game.get_player() command has been removed, so i will move this to 'resolved'
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1525
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: on_player_created, game.players and game.get_player

Post by binbinhfr »

Klonan wrote:Thanks for the report,

In 0.13 the game.get_player() command has been removed, so i will move this to 'resolved'
OK, thx Klonan.
I'm really impatient to get this 0.13 that will correct all these features I need for my future mod.
By the way, if you're looking for beta testers, I'm open to it.
My mods on the Factorio Mod Portal :geek:
Post Reply

Return to “Resolved Problems and Bugs”