[1.1.60] (modding-related) repeat guns on a car/spider-vehicle type "mess up" guns prototype value

Post Reply
Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

[1.1.60] (modding-related) repeat guns on a car/spider-vehicle type "mess up" guns prototype value

Post by Honktown »

1) LuaEntityPrototype->guns
guns
:: dictionary[string → LuaItemPrototype]
[R]

A mapping of the gun name to the gun prototype this prototype uses, or nil.
Reasoning: I have a mod which acts based on which gun is the next selectable after pressing "Next weapon". I was looking for a table which matched the selectable gun indices to names/prototypes. The prototype only has names (in index order) to gun prototypes.

Example code to cause the behavior:

Code: Select all

--somewhen during data:
local tank = data.raw.car.tank
tank.guns[2] = tank.guns[1]
local spider = data.raw["spider-vehicle"]["spidertron"]
spider.guns[2] = spider.guns[1]
In game:

Code: Select all

/c
local i = 0
local tick = game.tick
for k,v in pairs(game.entity_prototypes.tank.guns) do
	i = i + 1
	game.print(tick.." "..i.." "..k)
end

i = 0
for k,v in pairs(game.entity_prototypes.spidertron.guns) do
	i = i + 1
	game.print(tick.." "..i.." "..k)
end
Result:
lost_guns.jpg
lost_guns.jpg (55.29 KiB) Viewed 1010 times
Problem: repeated keys by nature of two guns having the same name "break" the returned table.
Expectation: Repeating guns isn't allowed, or the table should be index->gun matching selected_gun_index of an entity.

Note: My memory may be wrong, but I thought that repeated guns weren't allowed (hence why spidertrons have rocket launchers -1 -2 -3 -4). This may be a regression?
I have mods! I guess!
Link

Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: [1.1.60] (modding-related) repeat guns on a car/spider-vehicle type "mess up" guns prototype value

Post by Honktown »

I forgot to add:
The prototype explorer shows all the guns, and the guns are present on the vehicles.
I have mods! I guess!
Link

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2250
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.60] (modding-related) repeat guns on a car/spider-vehicle type "mess up" guns prototype value

Post by boskid »

Due to backward compatibility i cannot make `LuaEntityPrototype::guns` to be an array, but for 1.1.61 i implemented a `LuaEntityPrototype::indexed_guns`. It is basically the same but instead of returning a dictionary (indexed by gun name) it returns an array (indexed by the gun index). So i am considering this to be Implemented modding interface request and i am moving this out of Bug reports.

Post Reply

Return to “Implemented mod requests”