Add connection_distance and double joint_distance to LuaEntityPrototoype

Post Reply
tubs
Burner Inserter
Burner Inserter
Posts: 15
Joined: Tue Jan 06, 2015 7:29 pm
Contact:

Add connection_distance and double joint_distance to LuaEntityPrototoype

Post by tubs »

Hey, could we get:

Code: Select all

connection_distance	::	double
joint_distance	::	double
from https://wiki.factorio.com/Prototype/RollingStock

to be available from LuaEntityPrototype?

Thanks!
bubbels (sic)

User avatar
Templarfreak
Burner Inserter
Burner Inserter
Posts: 15
Joined: Thu Oct 05, 2017 2:21 pm
Contact:

Re: Add connection_distance and double joint_distance to LuaEntityPrototoype

Post by Templarfreak »

Any particular reason why you need this? Just exposing that data to LuaEntityPrototype is pretty unnecessary, you can actually attach any data you like to any data structure you like arbitrary, its one of the key features of Lua. For instance I do this in a personal mod to add a boolean to certain entities as an exception for whether or not they should be mined faster by hand.

If you're hoping for those to still be functional as you would expect they would be on trains, that is very unlikely to happen.

User avatar
mrudat
Fast Inserter
Fast Inserter
Posts: 229
Joined: Fri Feb 16, 2018 5:21 am
Contact:

Re: Add connection_distance and double joint_distance to LuaEntityPrototoype

Post by mrudat »

LuaEntityPrototype is the control-stage version of (for example) data.raw.locomotive. If you add a field in the data stage to data.raw.locomotive, eg:

Code: Select all

data.raw.locomotive.locomotive._MyModData = { --[[ Stuff my mod needs to know about locomotives ]] }
That'll work, and you can read the data back later, but it won't be added to the LuaEntityPrototype that you access while the game is actually in progress.

I honestly don't know if you can add a custom field to a LuaEntityPrototype, and I've never been inclined to find out.

It is rather fraught as LuaEntityPrototype is a temporary object created to allow you to access the internal entity_prototype that defines how an entity should behave; if the game configuration changes it's entirely possible that the particular LuaEntityPrototype that you've been hanging on to will become invalid, and when you retrieve a new one, the data you stored earlier will be gone.

In this particular case, these are existing values that are defined in the data phase and used by the game as part of simulating how trains work, they just happen to not be able to be retrieved during the control phase.

Edit: fix thinking misteak.

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

Re: Add connection_distance and double joint_distance to LuaEntityPrototoype

Post by Rseding91 »

Ok, I've added both of these for the next 1.1. release.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Implemented mod requests”