Page 1 of 1
[0.18.8] Prototype vehicle impact sound definitions should not use shared tables.
Posted: Mon Mar 02, 2020 10:38 am
by eradicator
What?
demo-sounds.lua should be a bunch of functions that return fresh copies of the respective sound presets.
Why?
Currently all prototypes share a reference to the same table, thus changes to one prototype inadvertently affect all prototypes.
A heavily simplified example that changes "sounds.generic_impact":
Code: Select all
for _,s in pairs(data.raw['electric-pole']['substation'].vehicle_impact_sound) do
s.filename = "__core__/sound/cannot-build.ogg"
s.volume = 1
end
--Oops, i just made almost every impact in the game sound annoying!
Re: [0.18.8] Prototype vehicle impact sound definitions should not use shared tables.
Posted: Mon Mar 02, 2020 10:40 am
by Klonan
This isn't a bug
Re: [0.18.8] Prototype vehicle impact sound definitions should not use shared tables.
Posted: Mon Mar 02, 2020 11:27 am
by darkfrei
I had the same problem with tiles graphics, they share some tables, but it was expected that they are not linked. Two hours to understand that my code was right, but vanilla prototypes are linked.
Re: [0.18.8] Prototype vehicle impact sound definitions should not use shared tables.
Posted: Mon Mar 02, 2020 11:27 am
by eradicator
Klonan wrote: Mon Mar 02, 2020 10:40 am
This isn't a bug
Yea but... It is as far as i can tell
a) the only place where multiple prototypes share a single table reference.
b) a cause of mod bugs
And it's hardly an "interface request" either. So. Meh.
Unless you meant "we don't care".
Re: [0.18.8] Prototype vehicle impact sound definitions should not use shared tables.
Posted: Mon Mar 02, 2020 11:40 am
by Deadlock989
That's how Lua works. Replace the whole value with a fresh table if you want to be certain of literally anything.
Re: [0.18.8] Prototype vehicle impact sound definitions should not use shared tables.
Posted: Mon Mar 02, 2020 12:29 pm
by posila
eradicator wrote: Mon Mar 02, 2020 11:27 am
a) the only place where multiple prototypes share a single table reference.
Circuit connector definitions are shared like this, water_tile_type_names are shared like this... those are ones that I know of.
I don't think it's a bug either, it's more for a discussion how these things should work.
Re: [0.18.8] Prototype vehicle impact sound definitions should not use shared tables.
Posted: Mon Mar 02, 2020 12:35 pm
by Bilka
posila wrote: Mon Mar 02, 2020 12:29 pm
eradicator wrote: Mon Mar 02, 2020 11:27 am
a) the only place where multiple prototypes share a single table reference.
Circuit connector definitions are shared like this, water_tile_type_names are shared like this... those are ones that I know of.
I don't think it's a bug either, it's more for a discussion how these things should work.
Some other definitions are shared by having a function return the table which in my opinion is ideal.
Re: [0.18.8] Prototype vehicle impact sound definitions should not use shared tables.
Posted: Tue Mar 03, 2020 1:52 am
by eradicator
posila wrote: Mon Mar 02, 2020 12:29 pm
I don't think it's a bug either, it's more for a discussion how these things should work.
I don't think it's a "bug" as such either (should've been more clear in the OP, sorry about that). But it is an annoying trap that is hard to notice and difficult to track down when you don't know what exactly you're looking for. So for lack of a "technical nitpicking" subforum i posted it here because it seemed the least unappropriate subforum. ("Ideas & Suggestsion" not being technical, and "interface requests" being unrelated).
Bilka wrote: Mon Mar 02, 2020 12:35 pm
Some other definitions are shared by having a function return the table which in my opinion is ideal.
Exactly my opinion.