Grabbing mining_target for an entity on creation

Place to get help with not working mods / modding interface.
redplasticstraw
Burner Inserter
Burner Inserter
Posts: 16
Joined: Fri Sep 15, 2023 12:01 pm
Contact:

Grabbing mining_target for an entity on creation

Post by redplasticstraw »

I'm having issues when trying to grab a mining-drill entity's mining target whenever it is created. It seems to only get it on the first tick it runs, even though it's a pump jack. I tried using find_entities_filtered on the area where it spawns, but it doesn't return what I need. It seems to return a userdata block thing that appears as a luaentity but isn't useful at all for table matching with pre-existing LuaEntity objects.

What should I do about this?

User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 401
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: Grabbing mining_target for an entity on creation

Post by Stringweasel »

redplasticstraw wrote:
Wed Aug 21, 2024 4:52 am
I tried using find_entities_filtered on the area where it spawns, but it doesn't return what I need. It seems to return a userdata block thing that appears as a luaentity but isn't useful at all for table matching with pre-existing LuaEntity objects.
I think here is the issue. If you can't get mining_target immediatelly then finding it manually as you did seems like the right approach. And you seem to have done it correctly, and just missinterpreted the results.

find_entities_filtered returns an array of LuaEntity, which is what you want. If you try to print or log this though then it shoes user-data-something, beause it's not a real table.
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Official Contributor to Space Exploration

redplasticstraw
Burner Inserter
Burner Inserter
Posts: 16
Joined: Fri Sep 15, 2023 12:01 pm
Contact:

Re: Grabbing mining_target for an entity on creation

Post by redplasticstraw »

It only becomes an issue because I have two separate scripts, one to store mining patches and one to store the machines that go on those mining patches. The way I had the patches indexed was by entity so I could use mining_target on the machines and just grab the associated patch, but it just looks like I'll have to use the filtered for both indexes instead of the actual entity itself.

Thanks!

User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 401
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: Grabbing mining_target for an entity on creation

Post by Stringweasel »

I see. What modders usually use is unit_number.
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Official Contributor to Space Exploration

Post Reply

Return to “Modding help”