on_player_banned nil player_index

Place to report issues and suggest improvements to the API documentation.
Loup&Snoop
Long Handed Inserter
Long Handed Inserter
Posts: 63
Joined: Wed Dec 04, 2024 4:33 am
Contact:

on_player_banned nil player_index

Post by Loup&Snoop »

I just got a crash from not understanding how this event fully works. Specifically, could this be added to the documentation for “player_index” in “on_player_banned”

“Index of the banned LuaPlayer. Is nil if the banned username isn’t tied to a player that ever joined the game.”

My own lack of experience with multiplayer led me to not know that it would be possible to ban a player who isn’t currently logged into the world. In my case, the user misspelled the user name.
Rseding91
Factorio Staff
Factorio Staff
Posts: 16258
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: on_player_banned nil player_index

Post by Rseding91 »

The event documentation already specifies the player_index as optional, if that was missed - would an extra comment about one of the ways it might not be provided be useful?

I’ve found when comments like that exist, people take them to mean “this is the *only* time this happens” when that isn’t guaranteed.
If you want to get ahold of me I'm almost always on Discord.
Loup&Snoop
Long Handed Inserter
Long Handed Inserter
Posts: 63
Joined: Wed Dec 04, 2024 4:33 am
Contact:

Re: on_player_banned nil player_index

Post by Loup&Snoop »

The main thing is: Since I don’t play multiplayer, I did not understand in what situation it could even be nil.

I can put in my own nil checks since it is listed as int or nil. But I still wouldn’t know what situations are getting caught in that nil check.

It may make sense to specify in the main event documentation (instead of the doc for the field) that “Players are banned by name (string), so there may be no matching LuaPlayer.” Or something like that. From this, I can reasonably infer the cases of misspelling or banning someone who never joined the game.
User avatar
MEOWMI
Filter Inserter
Filter Inserter
Posts: 371
Joined: Wed May 22, 2019 12:21 pm
Contact:

Re: on_player_banned nil player_index

Post by MEOWMI »

Rseding91 wrote: Wed Oct 29, 2025 10:19 pm I’ve found when comments like that exist, people take them to mean “this is the *only* time this happens” when that isn’t guaranteed.
I imagine that if it's worded like "for example..." then people will not assume that the examples shown are an exhaustive list of possible scenarios (at least I feel like it's very unambiguous).
curiosity
Filter Inserter
Filter Inserter
Posts: 702
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: on_player_banned nil player_index

Post by curiosity »

Rseding91 wrote: Wed Oct 29, 2025 10:19 pm The event documentation already specifies the player_index as optional, if that was missed - would an extra comment about one of the ways it might not be provided be useful?

I’ve found when comments like that exist, people take them to mean “this is the *only* time this happens” when that isn’t guaranteed.
If the player doesn't exist in the save is one case. What are the others? Seems to me there can't be that many.
Loup&Snoop wrote: Thu Oct 30, 2025 1:42 am The main thing is: Since I don’t play multiplayer, I did not understand in what situation it could even be nil.

I can put in my own nil checks since it is listed as int or nil. But I still wouldn’t know what situations are getting caught in that nil check.

It may make sense to specify in the main event documentation (instead of the doc for the field) that “Players are banned by name (string), so there may be no matching LuaPlayer.” Or something like that. From this, I can reasonably infer the cases of misspelling or banning someone who never joined the game.
That's a docs request, not an API request.
Loup&Snoop
Long Handed Inserter
Long Handed Inserter
Posts: 63
Joined: Wed Dec 04, 2024 4:33 am
Contact:

Re: on_player_banned nil player_index

Post by Loup&Snoop »

My mistake. I intended to post this in the API documentation request forum. I only noticed when Curiosity mentioned.

Could a moderator help me out by moving this thread to the doc request forum? EDIT: ty, mod
Post Reply

Return to “Documentation Improvement Requests”