[14.22] prepare_range on turrets.lua is redefined twice

This subforum contains all the issues which we already resolved.
User avatar
Dustine
Long Handed Inserter
Long Handed Inserter
Posts: 60
Joined: Tue Mar 31, 2015 4:52 pm
Contact:

[14.22] prepare_range on turrets.lua is redefined twice

Post by Dustine »

(Already seen on viewtopic.php?f=25&t=37246 but it was in Mod Discussion)

So while writing some stuff for a mod, I copied some field data from \data\base\prototypes\entity\turrets.lua and absent-mindely forgot about it until five minutes later when my lua linter was yelling at me about a variable's value being unused. Which was really weird, because I hadn't done anything in the file but tweak some values elsewhere.

Turns out, the issue came from the base prototype and the linter was being a bit obtuse: by a value not being used, it meant that it was being overridden. prepare_range is defined twice in the same prototype table, each time with different values.

Image
(this is inside medium-worm-turret, on turrets.lua)

This counts as a bug because the value that the game processes for data.raw.turret["medium-worm-turret"].prepare_range is 30, not 25, which may be unintended behaviour.

Just for curiosity I ran my linter, luacheck, to find more cases of this happening inside the prototype bases, and it found a few. I haven't looked at them yet personally, excluding the ones in turrets.lua*, the following report indicates the file and line number.

* The other times it happens in the turrets.lua file both instantiations have the same value, so it's not a bug but it's still kinda dirtied code.
Luacheck report for error code 314
posila
Former Staff
Former Staff
Posts: 5448
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [14.22] prepare_range on turrets.lua is redefined twice

Post by posila »

Thanks for the report, I went through your warnings and removed redefined properties for 0.15.3
Post Reply

Return to “Resolved Problems and Bugs”