How do I read sticker effects?

Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

How do I read sticker effects?

Post by Pi-C »

I'm trying to calculate the maximum speed of vehicles, depending on weight, friction, terrain, fuel etc. In addition to all these, vehicles can also be affected by stickers.

I can read what stickers are affecting a vehicle:

Code: Select all

for s, sticker in pairs(vehicle.stickers or {}) do
	game.print(sticker.name)
end
But I don't know how to go from there.

Let's take the acid-sticker-behemoth as an example. According to the prototype browser, it modifies friction:
acid-sticker.png
acid-sticker.png (102.73 KiB) Viewed 1199 times
Now, I can't read sticker.friction_modifier because only car prototypes have this property. Apparently, stickers attached to a car don't affect sticker.sticked_to.friction_modifier:

Code: Select all

/c p = game.player
    car = p.surface.create_entity{name = "car", position = {p.position.x-10, p.position.y}, force = p.force}
    old_friction = car.friction_modifier
    p.surface.create_entity{name = "acid-sticker-behemoth", position = car.position, target = car}
    game.print("Friction modifier before: "..old_friction.."\tafter: "..car.friction_modifier)
So, how do I get the effect the sticker has at a given time on the vehicle it's sticking to?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Bilka
Factorio Staff
Factorio Staff
Posts: 3139
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: How do I read sticker effects?

Post by Bilka »

Likely not the answer you want, but by making a modding interface request to be able to read it from the sticker prototype. I think it's not exposed on the prototype right now because it's linearly interpolated between the _from and _to values based on how much time to live the sticker has left, so it's not a straight up "just access the property" thing. Letting you know so you can figure out if you want to request that interpolated access or if you want the raw values. Or perhaps you want to read the resulting interpolated modifier from the entity, that should also be possible.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: How do I read sticker effects?

Post by Pi-C »

Thanks for your reply!
Bilka wrote:
Wed Jun 07, 2023 7:46 am
Letting you know so you can figure out if you want to request that interpolated access or if you want the raw values. Or perhaps you want to read the resulting interpolated modifier from the entity, that should also be possible.
For my own use case, reading the interpolated modifier from the entity (you do mean the sticker entity, right?) would be the most useful option as it would save me the work of calculating the current value.

Reading the raw values for modifiers from the sticker prototype wouldn't help much, I'm afraid. While we could store the time when the sticker was created, we still wouldn't be able to access Prototype/Sticker.duration_in_ticks yet, which we'd need for interpolating the values.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Bilka
Factorio Staff
Factorio Staff
Posts: 3139
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: How do I read sticker effects?

Post by Bilka »

Pi-C wrote:
Thu Jun 08, 2023 8:36 am
For my own use case, reading the interpolated modifier from the entity (you do mean the sticker entity, right?) would be the most useful option as it would save me the work of calculating the current value.
I meant the combined effects of the stickers, read from the entity the stickers are sticked to. For any devs looking at this: I would go LuaEntity -> getStickerInterface -> getVehicleModifiersFromStickers. But it could also be read from the sticker itself.
Pi-C wrote:
Thu Jun 08, 2023 8:36 am
Reading the raw values for modifiers from the sticker prototype wouldn't help much, I'm afraid. While we could store the time when the sticker was created, we still wouldn't be able to access Prototype/Sticker.duration_in_ticks yet, which we'd need for interpolating the values.
Insert text about making a request for that to be exposed here. You know what, I'm just going to move the thread to modding interface requests, it should be clear enough.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: How do I read sticker effects?

Post by Pi-C »

Bilka wrote:
Thu Jun 08, 2023 9:32 am
Pi-C wrote:
Thu Jun 08, 2023 8:36 am
For my own use case, reading the interpolated modifier from the entity (you do mean the sticker entity, right?) would be the most useful option as it would save me the work of calculating the current value.
I meant the combined effects of the stickers, read from the entity the stickers are sticked to.
Yes, that would be even better! :-)
Insert text about making a request for that to be exposed here. You know what, I'm just going to move the thread to modding interface requests, it should be clear enough.
Thanks! You've been too fast for me, I'll remove the request I've just posted myself. :-D
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: How do I read sticker effects?

Post by Rseding91 »

I've Added LuaEntity::sticker_vehicle_modifiers read for the next 1.1 release.
If you want to get ahold of me I'm almost always on Discord.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: How do I read sticker effects?

Post by Pi-C »

Rseding91 wrote:
Sat Oct 07, 2023 8:34 pm
I've Added LuaEntity::sticker_vehicle_modifiers read for the next 1.1 release.
Thank you! Just a question so I can prepare my mod for 1.1.93: In what format will LuaEntity::sticker_vehicle_modifiers return the data? I suppose it's a dictionary of modifier names mapped to float-type values. But if I'd want to read the value of the entities vehicle_speed_modifier, under what name exactly would I find it: "speed", "speed_modifier", "vehicle_speed_modifier", or something entirely different?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Bilka
Factorio Staff
Factorio Staff
Posts: 3139
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: How do I read sticker effects?

Post by Bilka »

Pi-C wrote:
Sun Oct 08, 2023 3:31 pm
Rseding91 wrote:
Sat Oct 07, 2023 8:34 pm
I've Added LuaEntity::sticker_vehicle_modifiers read for the next 1.1 release.
Thank you! Just a question so I can prepare my mod for 1.1.93: In what format will LuaEntity::sticker_vehicle_modifiers return the data? I suppose it's a dictionary of modifier names mapped to float-type values. But if I'd want to read the value of the entities vehicle_speed_modifier, under what name exactly would I find it: "speed", "speed_modifier", "vehicle_speed_modifier", or something entirely different?
It will indeed be the format you describe:
entity.sticker_vehicle_modifiers.speed_modifier and entity.sticker_vehicle_modifiers.friction_modifier.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: How do I read sticker effects?

Post by Pi-C »

Bilka wrote:
Sun Oct 08, 2023 5:43 pm
Pi-C wrote:
Sun Oct 08, 2023 3:31 pm
In what format will LuaEntity::sticker_vehicle_modifiers return the data? I suppose it's a dictionary of modifier names mapped to float-type values. But if I'd want to read the value of the entities vehicle_speed_modifier, under what name exactly would I find it: "speed", "speed_modifier", "vehicle_speed_modifier", or something entirely different?
It will indeed be the format you describe:
entity.sticker_vehicle_modifiers.speed_modifier and entity.sticker_vehicle_modifiers.friction_modifier.
Thanks for the info! I've just rewritten the function where I'll need this. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Implemented mod requests”