[1.1.60] (modding-related) repeat guns on a car/spider-vehicle type "mess up" guns prototype value
Posted: Wed Jun 15, 2022 10:58 pm
1) LuaEntityPrototype->guns
Example code to cause the behavior:
In game:
Result:
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?
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.guns
:: dictionary[string → LuaItemPrototype]
[R]
A mapping of the gun name to the gun prototype this prototype uses, or nil.
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]
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
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?