Reverse lookup: game.forces[force_index]

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Reverse lookup: game.forces[force_index]

Post by eradicator »

What?

Return the force when indexing game.forces with a force's index, the same as it works for game.players and game.surfaces.

Doesn't work:

Code: Select all

/c game.print(game.forces[game.forces['player'].index].name)
Works:

Code: Select all

/c game.print(game.surfaces[game.surfaces['nauvis'].index].name)
/c game.print(game.players[game.players[1].index].name)
Why?

I'm indexing some global tables by force index, and i'd like to get the force back without looping through all forces. Besides to me this was "unexpected behavior" as it works fine with players and surfaces.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14911
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Reverse lookup: game.forces[force_index]

Post by Rseding91 »

Ok, i've added support for it for the next version of 0.17.
If you want to get ahold of me I'm almost always on Discord.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Reverse lookup: game.forces[force_index]

Post by eradicator »

Thank you.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Post Reply

Return to “Implemented mod requests”