On_research_queued event

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
Theis
Inserter
Inserter
Posts: 27
Joined: Tue Sep 13, 2022 9:57 am
Contact:

On_research_queued event

Post by Theis »

What
I would like an event on_research_queued similar to on_research_started.
How
Fields:
  • research :: LuaTechnology -> the queued technology
  • queue_index :: uint -> the research queue index of the technology
  • name :: defines.event
  • tick :: uint
I can probably handle any implementation, but having the index would be neat for most uses.
Why
This is for my mod TAS step planner, where the mod records the players actions so they can be played back by a TAS.

In this case, it is possible to record starting a research but not the 2nd through 7th queued research.
Which means that the user of the mod either needs to cancel and start the next item to record. Or wait for the research to finish.

research_queue_recorder.png
research_queue_recorder.png (42.03 KiB) Viewed 907 times

curiosity
Filter Inserter
Filter Inserter
Posts: 325
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: On_research_queued event

Post by curiosity »

Pretty awful workaround, but you can poll force.research_queue every tick.

And what will you do if a research is unqueued? That would also need an event, or there can be a on_research_queue_changed event to cover both cases.

In fact, on_research_queue_changed will cover even such cases as mods setting the queue.

Theis
Inserter
Inserter
Posts: 27
Joined: Tue Sep 13, 2022 9:57 am
Contact:

Re: On_research_queued event

Post by Theis »

I don't particularly care about dequeued technologies, since cancelling research is easily done by going back in time and just not queuing it. But i can see why it would matter for other uses :)

on_research_queue_changed would need to have an indicator of the index and if the item was queued or dequeued.
However the developer might expect it to trigger when a research finishes too. Which is fairly well covered by on_research_finished and on_research_started
Maybe an on_player_changed_research_queue would have less overlap

Polling the queue every couple of ticks seems awful :(

curiosity
Filter Inserter
Filter Inserter
Posts: 325
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: On_research_queued event

Post by curiosity »

It's only a few slots long. Shouldn't be too costly. Alternatively, since you don't care about historical accuracy, you can poll it in on_research_finished or on_research_started. Or not at all, and just compress the actual researched techs into the queue when you reproduce the run.

Actually, I have done some testing and on_research_cancelled works with the queue, getting raised when a queued technology is cancelled (though it fails to get raised on script overwriting the queue). So on_research_queued that works similarly may be fine, while also making both events work with script.

Theis
Inserter
Inserter
Posts: 27
Joined: Tue Sep 13, 2022 9:57 am
Contact:

Re: On_research_queued event

Post by Theis »

I can try pulling the research queue, the next time I look at the mod.
on_research_finished and on_research_started doesn't really work for me. As that would mean the research tasks are added to the task list on a nearly random point.

PennyJim
Burner Inserter
Burner Inserter
Posts: 12
Joined: Wed Jan 18, 2023 3:49 am
Contact:

Re: On_research_queued event

Post by PennyJim »

I also would like an `on_research_queued` event.

I'm trying to re-implement multiplayer chat, and due to the fact that you can't modify messages I've been forced to clear chat and resend my own version.
Adding research to the queue is currently not something I can replicate. Due to this, the messages will get sent by the game, but cleared away the next time I send a message.
curiosity wrote:
Fri Mar 31, 2023 2:00 am
And what will you do if a research is unqueued?
There's on_research_cancelled, which I wish would include the player that cancelled it (if relevant)

Post Reply

Return to “Modding interface requests”