Page 1 of 1

LuaEntityPrototype doesn't contain key air_resistance.

Posted: Wed Dec 15, 2021 6:29 am
by Rafiz
But it should, right? In docs of LuaEntityPrototype it says LuaEntityPrototype has key air_resistance, that is either double value or nil.

my (kind of messy) mod control file. mod from mod portal isn't in newest(this) form
https://pastebin.com/5HcnzQzz
(as side note, line 47 prints that we are dealing with LuaEntityPrototype, same as error message, but just wanted to make sure)

my error (whenever train gets registered ( reload or new game->after placing train part ) ):

Code: Select all

Error while running event train_realism::on_tick (ID 0)
LuaEntityPrototype doesn't contain key air_resistance.
stack traceback:
	[C]: in function '__index'
	__train_realism__/control/debug_controller.lua:51: in function 'airResistance'
	__train_realism__/control/debug_controller.lua:86: in function 'calculateTrainAirResistance'
	__train_realism__/control/debug_controller.lua:142: in function 'createTrain'
	__train_realism__/control/debug_controller.lua:168: in function 'registerTrains'
	__train_realism__/control/debug_controller.lua:535: in function <__train_realism__/control/debug_controller.lua:530>
1365.478 Quitting: user-quit.
1365.691 Goodbye
I don't know, I think this error message is misleading. It states prototype doesn't have key that it ... really should have, according to API documentation.


Error started appearing after... I don't know, it just worked before. Now I can't place train

Re: LuaEntityPrototype doesn't contain key air_resistance.

Posted: Wed Dec 15, 2021 8:30 am
by Klonan
Are you sure you're calling it on a rolling stock, and not on some other type of entity prototype?

Also there is a direct link from entity to prototype,
so all the
`game.entity_prototypes[carriage.name]`

can be just
`carriage.prototype`

Re: LuaEntityPrototype doesn't contain key air_resistance.

Posted: Wed Dec 15, 2021 9:14 am
by Bilka
I cannot reproduce the issue with the pastebin code you provided. Furthermore, even if you were calling it on something that is not a rolling stock prototype (e.g. a character prototype), it should just return nil instead of erroring. So for me, this points to a broken install (try verifying files in steam) or you posted the wrong code/error. See boskid's post after mine.

Re: LuaEntityPrototype doesn't contain key air_resistance.

Posted: Wed Dec 15, 2021 9:29 am
by boskid
What version of factorio are you using? This field was added in 1.1.34.

Re: LuaEntityPrototype doesn't contain key air_resistance.

Posted: Wed Dec 15, 2021 11:01 am
by Rafiz
Actually, version must (indeed) be the problem! I'm using 1.1.33
My big mistake, for looking at newest stable API. I actually must change mod requirement to be >=1.1.34

I got fooled that this mod was working previously (on 1.1.33), but control.lua must have been omitted somehow in my previous mod edits, as now I even recall debug messages not being printed...
I was very confused that it stopped working after few mod edits, and that it stopped working in such way.

Thank you for help, and for game that has so excellent modding API.



Download speeds are extremally slow for me - only from factorio site : /