[boskid][1.1.109] LuaFluidBoxPrototype equality comparison is wrong

This subforum contains all the issues which we already resolved.
curiosity
Filter Inserter
Filter Inserter
Posts: 555
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

[boskid][1.1.109] LuaFluidBoxPrototype equality comparison is wrong

Post by curiosity »

To reproduce:
1. Install KS Power.
2. Start a new game, place KS Power's Oil Boiler. Observe that it has three distinct fluidboxes.
3. Execute command:

Code: Select all

/c local fbs = game.entity_prototypes['oil-steam-boiler'].fluidbox_prototypes game.print(fbs[1]==fbs[3])
Observe that it outputs true, thus the game claims those two fluidbox prototypes are equal when they obviously aren't.

Why this is a bug:
But you may look at those prototypes and object "They look the same, it's just comparing them field-by-field!". Except it's only some fields. Connections are different, don't count. Filters are different! Nope, irrelevant. It neither indicates that it's the same fluidbox prototype nor does it indicate that the two prototypes are interchangeable.

Expected behavior:
Equality comparison between two LuaObjects indicates that they both refer to the same underlying object. Or, if not that, at least some sane and meaningful result.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 3393
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [boskid][1.1.109] LuaFluidBoxPrototype equality comparison is wrong

Post by boskid »

Thanks for the report. This issue was already fixed "by accident" for 2.0 by other changes so i made a test for this to make sure it will stay fixed.

Core of the issue is that LuaFluidBoxPrototype equals operator checks if that lua object is binding to the same (EntityID, index) which by reading LuaFluidBoxPrototype::entity and LuaFluidBoxPrototype::index you can verify is equal, however it completly skips the fact that LuaFluidBoxPrototype has additional field which selects if the LuaFluidBoxPrototype points at the fluid box prototype of the energy source. One of those LuaFluidBoxPrototypes points at EnergySource's fluid box prototype while the other points at Entity's fluid box prototype, both being at the same index.

Anyway, fixed for 2.0.
curiosity
Filter Inserter
Filter Inserter
Posts: 555
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: [boskid][1.1.109] LuaFluidBoxPrototype equality comparison is wrong

Post by curiosity »

I appreciate the explanation. Looking forward to 2.0.
Post Reply

Return to “Resolved Problems and Bugs”