[0.18.8] Prototype vehicle impact sound definitions should not use shared tables.

Bugs that are actually features.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

[0.18.8] Prototype vehicle impact sound definitions should not use shared tables.

Post 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!
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.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: [0.18.8] Prototype vehicle impact sound definitions should not use shared tables.

Post 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.
Last edited by darkfrei on Mon Mar 02, 2020 11:28 am, edited 1 time in total.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [0.18.8] Prototype vehicle impact sound definitions should not use shared tables.

Post 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".
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.
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2529
Joined: Fri Nov 06, 2015 7:41 pm

Re: [0.18.8] Prototype vehicle impact sound definitions should not use shared tables.

Post by Deadlock989 »

That's how Lua works. Replace the whole value with a fresh table if you want to be certain of literally anything.
posila
Former Staff
Former Staff
Posts: 5448
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [0.18.8] Prototype vehicle impact sound definitions should not use shared tables.

Post 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.
Bilka
Factorio Staff
Factorio Staff
Posts: 3616
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: [0.18.8] Prototype vehicle impact sound definitions should not use shared tables.

Post 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.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [0.18.8] Prototype vehicle impact sound definitions should not use shared tables.

Post 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.
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 “Not a bug”