[2.0.12] Add LuaRecord.id and make LuaPlayer:cursor_record writable

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
zerwiport
Inserter
Inserter
Posts: 35
Joined: Sat Mar 09, 2024 11:03 pm
Contact:

[2.0.12] Add LuaRecord.id and make LuaPlayer:cursor_record writable

Post by zerwiport »

Hi, I'm working on Toolbars (floating quickbars) and would like to make it work as similar to the quickbar as possible.

To support records I need:
  • LuaRecord.id - to store it in a slot and retrieve from LuaPlayer:blueprints() when picked
  • LuaPlayer:cursor_record - write access to place it in the cursor
Xampa
Burner Inserter
Burner Inserter
Posts: 10
Joined: Sat Feb 23, 2013 3:43 pm
Contact:

Re: [2.0.12] Add LuaRecord.id and make LuaPlayer:cursor_record writable

Post by Xampa »

+
User avatar
Shemp
Inserter
Inserter
Posts: 29
Joined: Mon Jan 19, 2026 6:51 pm
Contact:

Re: [2.0.12] Add LuaRecord.id and make LuaPlayer:cursor_record writable

Post by Shemp »

I'm investigating how feasible it would be to add a feature like this for Compact Recipe Pins, for a similar purpose. I looked into Toolbars first to see if you had already done it, since it would be a more appropriate feature for that mod.

After seeing how constrained LuaRecord is in the API, I'll lend a +1 to this thread.

My plan with the current API is to obtain the record ID by converting LuaPlayer::cursor_record into a string with tostring(), which you can parse for the ID.
blueprint-id.png
blueprint-id.png (119.27 KiB) Viewed 102 times
The LuaRecord would get stored for later, and I could assign it to the player's cursor by exporting the record with LuaRecord::export_record(), then copying that to the cursor with LuaPlayer::cursor_stack.import_stack().

I would also need to come up with a way to render a blueprint icon with the correct display icons inside of a sprite-button, but I believe it's possible.

The main issue is, I don't know if the string output from converting the LuaRecord is deterministic. That is to say, different clients in a multiplayer game may see different numbered IDs, and accessing them would lead to desyncs.

It'd be nice to have some comment about whether this is safe to do, or my plans end here.

-------------

EDIT: Okay, a few days later, I have an implementation:
crp-record-pins.png
crp-record-pins.png (19.38 KiB) Viewed 33 times
If I may add another related suggestion, it would be the ability to open the editing GUI for a LuaRecord. This could be done through either:
  • A LuaRecord::open_gui function that accepts a LuaPlayer
  • Or be able to assign a LuaRecord to LuaPlayer::opened
If this is done using a LuaRecord that doesn't belong to that LuaPlayer, it should throw an error.
Post Reply

Return to “Modding interface requests”