[Rseding] [0.17.68] cursor_stack.valid_for_read false in mfd with cut-paste-tool in hand

This subforum contains all the issues which we already resolved.
quyxkh
Smart Inserter
Smart Inserter
Posts: 1031
Joined: Sun May 08, 2016 9:01 am
Contact:

[Rseding] [0.17.68] cursor_stack.valid_for_read false in mfd with cut-paste-tool in hand

Post by quyxkh »

Hit control X, enter the console, do

Code: Select all

/c game.print(game.player.cursor_stack.valid_for_read)
it prints "true".
Do

Code: Select all

/c
script.on_event(defines.events.on_marked_for_deconstruction, function(ev) 
        game.print(game.players[ev.player_index].cursor_stack.valid_for_read)
        end)
and use the cut-paste-tool you still have in hand, it prints "false" (edit: just checked, the player index is correct). Then enter the console (still with the same tool in hand), do the first command again, you get "true" again.

Unless I'm missing something, this makes it impossible to properly hook mfd for cutting.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [0.17.68] cursor_stack.valid_for_read false in mfd with cut-paste-tool in hand

Post by eradicator »

A little flow analysis.
  1. Press Ctrl+X to get the tool
  2. Mark something for deconstruction.
Event listeners:

Code: Select all

/c
--[[listener]]
local blacklist = {'on_tick','on_chunk_generated','on_entity_spawned','on_player_changed_position'}
for _,v in pairs(blacklist) do blacklist[v] = true end
local ename = {}; for k,v in pairs(defines.events) do ename[v] = k end
script.on_event(defines.events,function(e) if not blacklist[ename[e.name]] then printer(ename[e.name]) end end)

--[[debug printer]]
x = game.player.cursor_stack
function printer(event_name)
  local y = x.valid_for_read
  print(game.tick,event_name,y and x.name,y and x.name == 'blueprint' and #x.get_blueprint_entities())
  end
Result:

Code: Select all

2505    on_player_cursor_stack_changed  cut-paste-tool  false
2633    on_player_setup_blueprint       blueprint       1
2633    on_marked_for_deconstruction    false   false
2633    on_player_cursor_stack_changed  blueprint       1
This looks strange as the cursor stack is a setup blueprint *before* the decon event and after it, but not during it. And on_cursor_stack_changed is *not* raised to signal the empty cursor stack.
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.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14345
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [Rseding] [0.17.68] cursor_stack.valid_for_read false in mfd with cut-paste-tool in hand

Post by Rseding91 »

Thanks for the report. While not a bug I didn't see any reason to not have the cursor stack still show the cut-paste tool during the cut portion of the logic so I've changed it to do that for the next version of 0.17.
If you want to get ahold of me I'm almost always on Discord.
quyxkh
Smart Inserter
Smart Inserter
Posts: 1031
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: [Rseding] [0.17.68] cursor_stack.valid_for_read false in mfd with cut-paste-tool in hand

Post by quyxkh »

Thanks for making it all pretty.
Rseding91 wrote: Fri Sep 13, 2019 2:40 amnot a bug
Hunh. Wasn't expecting that. Is (was, now) there some other way for a mod to tell what's in the player's hand when hooking the effects of a player using it, then? I confess I take it for granted there should be _some_ way, is that not right? Y'all are busy and these aren't much more than idle curiosity, I can't figure what led you to say that is all. Correcting my inability is of course vitally crucial to the state of the world.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14345
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [Rseding] [0.17.68] cursor_stack.valid_for_read false in mfd with cut-paste-tool in hand

Post by Rseding91 »

I said it wasn't a bug because at no point in designing how cut-paste should work did we decide that during cutting the cursor should have the cut-paste tool item in it. The cut-paste logic works correctly without that. Lua event logic was not part of the design process for it.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Resolved Problems and Bugs”