Page 1 of 1

Grabbing mining_target for an entity on creation

Posted: Wed Aug 21, 2024 4:52 am
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?

Re: Grabbing mining_target for an entity on creation

Posted: Wed Aug 21, 2024 7:19 am
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.

Re: Grabbing mining_target for an entity on creation

Posted: Wed Aug 21, 2024 3:00 pm
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!

Re: Grabbing mining_target for an entity on creation

Posted: Wed Aug 21, 2024 6:16 pm
by Stringweasel
I see. What modders usually use is unit_number.