[0.14.6] built_by -> last_user

Place to get help with not working mods / modding interface.
apriori
Filter Inserter
Filter Inserter
Posts: 282
Joined: Thu Feb 18, 2016 8:13 pm
Contact:

[0.14.6] built_by -> last_user

Post by apriori »

How should I make my mod compatible with pre-0.14.6 Factorio versions?

Code: Select all

  if event.created_entity.built_by then --or if event.created_entity["built_by"] then - this row is bad
      local player = event.created_entity.built_by --pre-0.14.6 compatibility
  else
      local player = event.created_entity.last_user
  end
raises an event.
Any code or mods posted by me are WTFPL, unless otherwise copyrights are specified.
Zeblote
Filter Inserter
Filter Inserter
Posts: 973
Joined: Fri Oct 31, 2014 11:55 am
Contact:

Re: [0.14.6] built_by -> last_user

Post by Zeblote »

I think the idea is more like "nobody cares about old versions". If someone is using experimental with mods at all, they can just run the latest one.
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: [0.14.6] built_by -> last_user

Post by Adil »

By determining the version of the "base" mod.
Factorio objects have always been raising error when checked for unexistant fields.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
apriori
Filter Inserter
Filter Inserter
Posts: 282
Joined: Thu Feb 18, 2016 8:13 pm
Contact:

Re: [0.14.6] built_by -> last_user

Post by apriori »

Adil wrote:By determining the version of the "base" mod.
Thanks.
Any code or mods posted by me are WTFPL, unless otherwise copyrights are specified.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: [0.14.6] built_by -> last_user

Post by aubergine18 »

This will get player regardless of version, because `last_user` will be `nil` on older versions and thus default to `built_by`. On new version or later, it will use `last_user`.

Code: Select all

local entity = event.created_entity
local player = entity.last_user or entity.built_by
BTW, you can also set more specific `factorio_version` in the `info.json` (just that most people don't use it), for example look at my Glyph mod in mod portal, I do that with this line in `info.json`:

Code: Select all

  "factorio_version": "0.14.3"
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15984
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.14.6] built_by -> last_user

Post by Rseding91 »

aubergine18 wrote:This will get player regardless of version, because `last_user` will be `nil` on older versions and thus default to `built_by`. On new version or later, it will use `last_user`.

Code: Select all

local entity = event.created_entity
local player = entity.last_user or entity.built_by
BTW, you can also set more specific `factorio_version` in the `info.json` (just that most people don't use it), for example look at my Glyph mod in mod portal, I do that with this line in `info.json`:

Code: Select all

  "factorio_version": "0.14.3"
The API doesn't work that way. If you call a property/function that doesn't exist on the object it gives an error.
If you want to get ahold of me I'm almost always on Discord.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: [0.14.6] built_by -> last_user

Post by aubergine18 »

Rseding91 wrote:The API doesn't work that way. If you call a property/function that doesn't exist on the object it gives an error.
Ah, never realised that. It's good as it means modders will instantly know if they mistype a property name or if a new release removes a property = faster bug identification and fixing.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Post Reply

Return to “Modding help”