Page 1 of 1

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

Posted: Tue Sep 10, 2019 11:54 am
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.

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

Posted: Tue Sep 10, 2019 12:33 pm
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.

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

Posted: Fri Sep 13, 2019 2:40 am
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.

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

Posted: Fri Sep 13, 2019 2:59 am
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.

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

Posted: Fri Sep 13, 2019 3:43 am
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.