Feature request for the mod: bobinserters

Some mods, made by Bob. Basically streaks every Factroio-area.

Moderator: bobingabout

Post Reply
User avatar
AmatorPhasma
Fast Inserter
Fast Inserter
Posts: 126
Joined: Sat Aug 05, 2017 8:20 pm
Contact:

Feature request for the mod: bobinserters

Post by AmatorPhasma »

Hi bobingabout,

I would like to ask if it would be possible that your mod raises a script event after manipulating inserters pickup and/or drop positions? or after closing your ui?

Why?
One of my mod adds the ability to inserters to clear/take from the burnt fuel inventory, but I don't iterate through all inserters, and remove all inserters that dosen't have a valid pickup target (a machine with a burnt_fuel _inventory), I maintain this list after rotating an inserter, build an inserter or build this kind of machine in the range of an inserter.

The Problem why I'm asking you for this script event is, as an example:
- if a player changes the pickup position through your ui to a position where no machine is (on the floor next to a machine), it can happen that my script removes this inserter from the list in a tick where it processes this inserter.
- If then a player change it back to pick up from this machine again, my script has no indication about this.

If you can raise a script event after modifying the positions, I can hook onto this event and my script can check if it needs to process this inserter again or not.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 6960
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by bobingabout »

AmatorPhasma wrote:
Wed Dec 25, 2019 11:32 pm
Hi bobingabout,

I would like to ask if it would be possible that your mod raises a script event after manipulating inserters pickup and/or drop positions? or after closing your ui?

Why?
One of my mod adds the ability to inserters to clear/take from the burnt fuel inventory, but I don't iterate through all inserters, and remove all inserters that dosen't have a valid pickup target (a machine with a burnt_fuel _inventory), I maintain this list after rotating an inserter, build an inserter or build this kind of machine in the range of an inserter.

The Problem why I'm asking you for this script event is, as an example:
- if a player changes the pickup position through your ui to a position where no machine is (on the floor next to a machine), it can happen that my script removes this inserter from the list in a tick where it processes this inserter.
- If then a player change it back to pick up from this machine again, my script has no indication about this.

If you can raise a script event after modifying the positions, I can hook onto this event and my script can check if it needs to process this inserter again or not.
It's a valid request.
I haven't done any custom events before, but that's mostly because they're a pain in the ass to get to work properly. Since they're created dynamically when you load a game, they're one of the few things that need to be created and linked into in the on_load script, which has so many caveats around it's use. I always managed to find an alternate method to do things.
what you're requesting, which is a very valid and doable request, can only really be done with custom events.

Anyway, the way my mod works, is that when you press any button, on the keyboard or a GUI that changes something, it happens instantly. So an event on the close button probably isn't needed.
From what I can gather from the description of your problem, you only really need an event raising when the pickup location is moved. though if I'm doing one for pickup, might as well also do one for drop.

I'm not sure when I'll get around to looking into this, but I'll put it on my list.

There's actually more than one mod that can change the location too... As far as I know, you can't re-use the events from a different mod because of the way they're done.

my Logistics mod, IF the Inserters mod isn't installed (So in theory, you'll only need to track one of them, but look in two places to set it up) has a button to change any inserter into a long handed version IF you have inserter overhaul turned on. This of course will change the pickup and dropoff locations of an inserter.


A good question is if you'd rather have a single "Hands changed" event raised, or a seperate event for pickup and drop.
on top of that, what values would you want the event to return? As absolute minimum, it would need to return the inserter entity.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
AmatorPhasma
Fast Inserter
Fast Inserter
Posts: 126
Joined: Sat Aug 05, 2017 8:20 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by AmatorPhasma »

Hi,
bobingabout wrote:
Sat Dec 28, 2019 12:52 pm
From what I can gather from the description of your problem, you only really need an event raising when the pickup location is moved. though if I'm doing one for pickup, might as well also do one for drop.
...
A good question is if you'd rather have a single "Hands changed" event raised, or a seperate event for pickup and drop.
on top of that, what values would you want the event to return? As absolute minimum, it would need to return the inserter entity.
Yes for my purpose it only needs one event with the entity.
But if I had to decide this on my own code I would implement it more general: event{entity, old_pickup, old_drop}, so it only needs one event because other mods can simple check which one has changed, or you can set the one that hasn't changed to nil example: event{entity:: LuaEntity, old_pickup:: Position or nil, old_drop:: Position or nil}
Or event{entity:: LuaEntity, type:: Int[0,1], old_position:: Position} where type=0 is pickup position and type=1 is drop position.
bobingabout wrote:
Sat Dec 28, 2019 12:52 pm
There's actually more than one mod that can change the location too... As far as I know, you can't re-use the events from a different mod because of the way they're done.
I think a "hacky?" solution could it be that you implement the custom event in your lib, and you call this event by a remote call from the other mods, so you expose only one event for the same type in all your mods. A side effect is that every mod that relay on your lib could remote call this event too. (But this is only an unproofed idea out of thin air, right now. I haven't had this question in my mods yet, they only raise mod explicit custom events.)
bobingabout wrote:
Sat Dec 28, 2019 12:52 pm
my Logistics mod, IF the Inserters mod isn't installed (So in theory, you'll only need to track one of them, but look in two places to set it up) has a button to change any inserter into a long handed version IF you have inserter overhaul turned on. This of course will change the pickup and dropoff locations of an inserter...
Oh I'm totally missed this because, I always play with at least the Inserters mod installed.
bobingabout wrote:
Sat Dec 28, 2019 12:52 pm
I'm not sure when I'll get around to looking into this, but I'll put it on my list.
Thanks for this :)

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 6960
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by bobingabout »

Another question would be... should the returned positions be relative [-1, 0] (from inserter middle) or absolute [236.5, -782345.5] (map co-ordinate) values.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
AmatorPhasma
Fast Inserter
Fast Inserter
Posts: 126
Joined: Sat Aug 05, 2017 8:20 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by AmatorPhasma »

bobingabout wrote:
Sat Dec 28, 2019 3:31 pm
Another question would be... should the returned positions be relative [-1, 0] (from inserter middle) or absolute [236.5, -782345.5] (map co-ordinate) values.
for inserters

Code: Select all

entity.pickup_position
entity.drop_position 
entity.held_stack_position
they return relative positions, so I would also return relative positions in your event.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 6960
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by bobingabout »

AmatorPhasma wrote:
Sat Dec 28, 2019 4:00 pm
bobingabout wrote:
Sat Dec 28, 2019 3:31 pm
Another question would be... should the returned positions be relative [-1, 0] (from inserter middle) or absolute [236.5, -782345.5] (map co-ordinate) values.
for inserters

Code: Select all

entity.pickup_position
entity.drop_position 
entity.held_stack_position
they return relative positions, so I would also return relative positions in your event.
it's what I was thinking.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
AmatorPhasma
Fast Inserter
Fast Inserter
Posts: 126
Joined: Sat Aug 05, 2017 8:20 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by AmatorPhasma »

wow...

I have no idea why I was thinking that the positions are relative,
they are map coordinates, sorry, no idea what my brain was doing as I wrote this :shock:

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 6960
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by bobingabout »

AmatorPhasma wrote:
Sun Dec 29, 2019 8:16 am
wow...

I have no idea why I was thinking that the positions are relative,
they are map coordinates, sorry, no idea what my brain was doing as I wrote this :shock:
I know what you said, but I know what you meant though.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 6960
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by bobingabout »

I'm working on this for the 0.18 update:

define what you want to happen when inserter hand positions change in a function, and define a setup for it in on_load and on_init as I demonstrate in this code snippet:

Code: Select all

function on_changed_inserter_positions(event)
  -- Code that does stuff when inserter positions changed goes here
end

function setup_on_changed_inserter_positions()
  if remote.interfaces.bobinserters then
 --these call the function when the event triggers, last variable matches the function name above.
     script.on_event(remote.call("bobinserters", "get_changed_position_event_id"), on_changed_inserter_positions)
  elseif remote.interfaces.boblogistics then
    script.on_event(remote.call("boblogistics", "get_changed_position_event_id"), on_changed_inserter_positions)
  end
end

script.on_init(function() --setup on starting new game
  setup_on_changed_inserter_positions()
  --other on_init stuff can be in here too
end)

script.on_load(function() --setup on loading existing game
  setup_on_changed_inserter_positions()
  --other on_load stuff can be in here too
end)
The data table (variable in my example named event) will return data in this structure:

Code: Select all

 {entity = entity, new_positions = {drop_position = {x,y}, pickup_position = {x,y}}, original_positions = {drop_position = {x,y}, pickup_position = {x,y}}}
In theory you could just read the new positions from event.entity.drop_position and event.entity.pickup_position, but I also included it as an extra variable.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
AmatorPhasma
Fast Inserter
Fast Inserter
Posts: 126
Joined: Sat Aug 05, 2017 8:20 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by AmatorPhasma »

Thank you very much for this! :)

I'm currently also work on my mods for 0.18
found some small (stupidity by me) bugs with the changed base game icons / mips and some of my color mask and icon overlays.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 6960
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by bobingabout »

what I've written is the intention, but currently when I have a this event for testing:

Code: Select all

script.on_event(changed_position_event, function(event)
  log(serpent.block(event))
end)
which should in theory log every time I change a hand... just logs blank every tick... so, I'm doing SOMETHING wrong. (the event is just running every tick, with no data)
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 6960
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by bobingabout »

AmatorPhasma wrote:
Wed Jan 22, 2020 8:06 pm
Thank you very much for this! :)

I'm currently also work on my mods for 0.18
found some small (stupidity by me) bugs with the changed base game icons / mips and some of my color mask and icon overlays.
Okay, I got it to work, the solution isn't exactly what I expected, so, look at my edited post for recommended usage.
though, seems to only work if you've actually loaded a game, I'm still experimenting to figure out how to make it work from the start.

EDIT: Fixed it by also including it in on_tick when event.tick == 2.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
AmatorPhasma
Fast Inserter
Fast Inserter
Posts: 126
Joined: Sat Aug 05, 2017 8:20 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by AmatorPhasma »

bobingabout wrote:
Wed Jan 22, 2020 9:43 pm
AmatorPhasma wrote:
Wed Jan 22, 2020 8:06 pm
Thank you very much for this! :)

I'm currently also work on my mods for 0.18
found some small (stupidity by me) bugs with the changed base game icons / mips and some of my color mask and icon overlays.
Okay, I got it to work, the solution isn't exactly what I expected, so, look at my edited post for recommended usage.
though, seems to only work if you've actually loaded a game, I'm still experimenting to figure out how to make it work from the start.

EDIT: Fixed it by also including it in on_tick when event.tick == 2.
Thanks again!

I implemented it in my mod and wait until I can test it live.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 6960
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by bobingabout »

AmatorPhasma wrote:
Wed Jan 22, 2020 10:30 pm
bobingabout wrote:
Wed Jan 22, 2020 9:43 pm
AmatorPhasma wrote:
Wed Jan 22, 2020 8:06 pm
Thank you very much for this! :)

I'm currently also work on my mods for 0.18
found some small (stupidity by me) bugs with the changed base game icons / mips and some of my color mask and icon overlays.
Okay, I got it to work, the solution isn't exactly what I expected, so, look at my edited post for recommended usage.
though, seems to only work if you've actually loaded a game, I'm still experimenting to figure out how to make it work from the start.

EDIT: Fixed it by also including it in on_tick when event.tick == 2.
Thanks again!

I implemented it in my mod and wait until I can test it live.
Looking at your mod, you may want to add this line to your on_tick event in control.lua

Code: Select all

  if event.tick == 2 then inserter.register_to_mod_events() end
without it, the required event won't actually run in new games until you save and load them.
(since it uses event.tick to make sure it only runs on tick 2 after the game is fully set up, and your inserter.on_tick() doesn't have any variables passed to it, you can't add it there)
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
AmatorPhasma
Fast Inserter
Fast Inserter
Posts: 126
Joined: Sat Aug 05, 2017 8:20 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by AmatorPhasma »

bobingabout wrote:
Wed Jan 22, 2020 11:17 pm

Code: Select all

  if event.tick == 2 then inserter.register_to_mod_events() end
For sure?
I ask because for Warptorio2, Portals, and my Starfall mod, it was always enough to have the hook to custom events in script.on_load() and script.on_init()

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 6960
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by bobingabout »

AmatorPhasma wrote:
Thu Jan 23, 2020 12:16 am
bobingabout wrote:
Wed Jan 22, 2020 11:17 pm

Code: Select all

  if event.tick == 2 then inserter.register_to_mod_events() end
For sure?
I ask because for Warptorio2, Portals, and my Starfall mod, it was always enough to have the hook to custom events in script.on_load() and script.on_init()
I did try in on_init, and it didn't work for me. it could have something to do with mod load order?
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
AmatorPhasma
Fast Inserter
Fast Inserter
Posts: 126
Joined: Sat Aug 05, 2017 8:20 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by AmatorPhasma »

bobingabout wrote:
Thu Jan 23, 2020 1:16 am
AmatorPhasma wrote:
Thu Jan 23, 2020 12:16 am
bobingabout wrote:
Wed Jan 22, 2020 11:17 pm

Code: Select all

  if event.tick == 2 then inserter.register_to_mod_events() end
For sure?
I ask because for Warptorio2, Portals, and my Starfall mod, it was always enough to have the hook to custom events in script.on_load() and script.on_init()
I did try in on_init, and it didn't work for me. it could have something to do with mod load order?
I tested it with warptorio.

Normaly warptorio script loaded before my starfall mod.
I edited warptorio with my mod as depenency, so it loads after my mods,
in both cases the hook to the event worked, even if the warptorio script is definitely initialized after my scripts.

Before my depenency edit with a new game:
============================================

Code: Select all

...
37.716 Checksum for script __apm_lib__/control.lua: 1306795716
37.731 Checksum for script __warptorio2__/control.lua: 2759814506
37.733 Checksum for script __apm_power__/control.lua: 735419581
37.734 Checksum for script __apm_nuclear__/control.lua: 1147008456
37.736 Checksum for script __apm_starfall__/control.lua: 1198283623
44.750 Script @__apm_lib__/lib/script/starfall.lua:165: Info: add_surface(): added: surface: "nauvis" with index: "1"
44.751 Script @__apm_lib__/lib/script/starfall.lua:846: Info: starfall.register_to_mod_events(): register events for "warptorio2"
...
51.454 Script @__apm_lib__/lib/script/starfall.lua:574: Info: event_queue_add(): for surface: "nauvis" with index: "1" at tick: "1181"
I triggered a warp ingame, this leads into an event from warptorio that I use to unregister and register a surface

Code: Select all

59.655 Script @__apm_lib__/lib/script/starfall.lua:179: Info: remove_event_by_surface_index(): removed event for surface with index: "1"
59.655 Script @__apm_lib__/lib/script/starfall.lua:194: Info: remove_surface(): removed: surface with index: "1"
59.655 Script @__apm_lib__/lib/script/starfall.lua:165: Info: add_surface(): added: surface: "warpsurf_1" with index: "5"

After my depenency edit with a new game:
============================================

Code: Select all

...
  20.648 Checksum for script __apm_lib__/control.lua: 1306795716
  20.650 Checksum for script __apm_power__/control.lua: 735419581
  20.651 Checksum for script __apm_nuclear__/control.lua: 1147008456
  20.653 Checksum for script __apm_starfall__/control.lua: 1198283623
  20.667 Checksum for script __warptorio2__/control.lua: 2759814506
  20.676 Script @__apm_lib__/lib/script/starfall.lua:165: Info: add_surface(): added: surface: "nauvis" with index: "1"
  20.677 Script @__apm_lib__/lib/script/starfall.lua:846: Info: starfall.register_to_mod_events(): register events for "warptorio2"
  33.086 Script @__apm_lib__/lib/script/starfall.lua:574: Info: event_queue_add(): for surface: "nauvis" with index: "1" at tick: "1181"
I triggered a warp ingame, this leads into an event from warptorio that I use to unregister and register a surface

Code: Select all

  34.993 Script @__apm_lib__/lib/script/starfall.lua:179: Info: remove_event_by_surface_index(): removed event for surface with index: "1"
  34.993 Script @__apm_lib__/lib/script/starfall.lua:194: Info: remove_surface(): removed: surface with index: "1"
  34.993 Script @__apm_lib__/lib/script/starfall.lua:165: Info: add_surface(): added: surface: "warpsurf_1" with index: "5"
  34.993 Script @__apm_lib__/lib/script/starfall.lua:574: Info: event_queue_add(): for surface: "warpsurf_1" with index: "5" at tick: "13108"
SO I would conclude it's not the load order... strange.. :geek:

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 6960
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by bobingabout »

AmatorPhasma wrote:
Thu Jan 23, 2020 2:04 am
For sure?
I ask because for Warptorio2, Portals, and my Starfall mod, it was always enough to have the hook to custom events in script.on_load() and script.on_init()
Perhaps it's not load order...
Basically, since building an inserter then editing it's hands is pretty easy in a new game, I added, in my clock mod (because it was a mod that already had scripts, I was doing it outside of inserters mod to simulate someone adding it to their mod) an event script that prints something (game.print) when the event is triggered.
Then I went and started a new game, and built an inserter, then edited it.

New game didn't work (editing the inserters didn't give a message), loaded from save game did. (editing the inserters gave a message)
So I added on_init to the same results.
So I added the on_tick where event.tick == 2 and it did work.

HOWEVER
I realise that I was probably overwriting it with a different on_init function later on, so, maybe putting it in on_init does work, and I was just already too tired and annoyed that it took this long to even get it working at all (with on_load when loading a game) to figure it out.

I can confirm after testing again now adding it to the existing on_init instead of making a second one that it does work.

Sorry for the confusion
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
AmatorPhasma
Fast Inserter
Fast Inserter
Posts: 126
Joined: Sat Aug 05, 2017 8:20 pm
Contact:

Re: Feature request for the mod: bobinserters

Post by AmatorPhasma »

bobingabout wrote:
Thu Jan 23, 2020 9:35 am
...
HOWEVER
I realise that I was probably overwriting it with a different on_init function later on, so, maybe putting it in on_init does work, and I was just already too tired and annoyed that it took this long to even get it working at all (with on_load when loading a game) to figure it out.

I can confirm after testing again now adding it to the existing on_init instead of making a second one that it does work.

Sorry for the confusion
Thanks for that info.
bobingabout wrote:
Thu Jan 23, 2020 9:35 am
(...) just already too tired and annoyed (...)
Thats how I feel now trying to understand what LUT is, and if I realy need this for my sprites :)

Post Reply

Return to “Bob's mods”

Who is online

Users browsing this forum: No registered users