LuaPlayer::get_hand_index / LuaPlayer::set_hand_index or similar

Post Reply
dewiniaid
Long Handed Inserter
Long Handed Inserter
Posts: 96
Joined: Tue Mar 07, 2017 8:50 pm
Contact:

LuaPlayer::get_hand_index / LuaPlayer::set_hand_index or similar

Post by dewiniaid »

Currently, there is no mechanism for a mod to select an item in the player's inventory using the exact same logic as a player clicking it. The current 'cleanest' method appears to be some variation upon:

Code: Select all

stack = player.get_inventory(defines.inventory.inventory_main)[index]
if player.clean_cursor() then
   player.cursor_stack.swap_stack(index)
end
However, this has a few problems:
  • There is no hand in the inventory, thus the space for the newly selected item is not reserved.
  • There is no guarantee the selected item will be returned to the same inventory slot after it is 'dropped'. (Mostly pertinent to manually-sorted inventories.)
  • It's far too easy for a mod author to accidentally destroy inventory contents (i.e. by forgetting to check if clean_cursor() actually succeeded.)

Note: I had previously requested a LuaPlayer::set_selected_index. There used to be a LuaPlayer::get_selected_index, but that appears to be gone as of 0.17

User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 450
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Re: LuaPlayer::get_hand_index / LuaPlayer::set_hand_index or similar

Post by raiguard »

Bump. I'm working on inventory and cursor stack synchronization between the editor and normal play, and when the inventory gets transferred when you switch, the hand disappears. It would be nice if I could set a stack to be the "hand" so that parity is maintained when switching modes.
Don't forget, you're here forever.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13202
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: LuaPlayer::get_hand_index / LuaPlayer::set_hand_index or similar

Post by Rseding91 »

Raiguard wrote:
Thu Feb 20, 2020 2:54 am
Bump. I'm working on inventory and cursor stack synchronization between the editor and normal play, and when the inventory gets transferred when you switch, the hand disappears. It would be nice if I could set a stack to be the "hand" so that parity is maintained when switching modes.
Off topic, that made me chuckle :D The editor specifically goes out of its way to avoid having the "normal" gameplay and items be polluted by the "editor" version and vice versa.
If you want to get ahold of me I'm almost always on Discord.

User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 450
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Re: LuaPlayer::get_hand_index / LuaPlayer::set_hand_index or similar

Post by raiguard »

Rseding91 wrote:
Thu Feb 20, 2020 5:10 pm
Off topic, that made me chuckle :D The editor specifically goes out of its way to avoid having the "normal" gameplay and items be polluted by the "editor" version and vice versa.
Yeah, normally I agree that having the editor and normal play be separated is a good thing. But many people want to be able to use a character and only use the editor when needed, so I'm making that playstyle easier.

By default, the feature is off. It's only active if the player is in cheat mode.
Don't forget, you're here forever.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: LuaPlayer::get_hand_index / LuaPlayer::set_hand_index or similar

Post by eradicator »

Huh, looks similar to my request (which was originally modding help): viewtopic.php?f=28&t=77097

+1
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Jorn86
Long Handed Inserter
Long Handed Inserter
Posts: 70
Joined: Sun May 01, 2016 7:08 pm
Contact:

Re: LuaPlayer::get_hand_index / LuaPlayer::set_hand_index or similar

Post by Jorn86 »

From the changelog description, I was hoping this would give me a way to read the player's actual mouse cursor without them triggering an action (like use capsule).

Oh well.

Post Reply

Return to “Implemented mod requests”