Page 1 of 1
[1.1.32] fast-transfer ignores LuaPlayer.selected = nil
Posted: Sun Apr 25, 2021 10:15 am
by eradicator
What?
Fast transfer (Ctrl+LMB) seems to be doing it's own collision box checking instead of respecting that the player has nothing selected.
Expected behavior
If the player has nothing selected then they shouldn't be able to fast-transfer.
Reproduction
Code: Select all
/c
script.on_event(defines.events.on_tick, function(e)
for _, p in pairs(game.players) do
p.selected = nil
end
end)
- Start a new game.
- Script force selection to nil. (command or demo mod)
- Take a stack and insert it into the spaceship.
- Take the stack back out if you want.
Re: [1.1.32] fast-transfer ignores LuaPlayer.selected = nil
Posted: Sun Apr 25, 2021 5:51 pm
by Rseding91
Thanks for the report however it doesn't ignore it. When the action runs there is a selected entity, then on_tick happens and it's cleared, the next tick it's re-found and the cycle repeats.
There's currently no way to fully disable entity selection since that's an intricate part of how the game functions.
Re: [1.1.32] fast-transfer ignores LuaPlayer.selected = nil
Posted: Sun Apr 25, 2021 7:25 pm
by Xorimuth
From my testing, it seems to work how you want it when you use `defines.events.on_selected_entity_changed` in a mod. Using it in the command input doesn't seem to do
anything (maybe I'm doing this bit wrong?). I can reproduce your issues when I use `on_tick` though.
Re: [1.1.32] fast-transfer ignores LuaPlayer.selected = nil
Posted: Sun Apr 25, 2021 9:12 pm
by eradicator
Xorimuth wrote: ↑Sun Apr 25, 2021 7:25 pm
From my testing, it seems to work how you want it when you use `defines.events.on_selected_entity_changed` in a mod.
That is actually exactly what I was doing when I first encountered the issue. Upon further testing that works for all items except for items with the
infamous "only-in-cursor" flag.
Rseding91 wrote: ↑Sun Apr 25, 2021 5:51 pm
There's currently no way to fully disable entity selection
Game_view_settings does this as far as I know, but completely disabling it does not work for my usecase this time.
Rseding91 wrote: ↑Sun Apr 25, 2021 5:51 pm
Thanks for the report however it doesn't ignore it. When the action runs there is a selected entity, then on_tick happens and it's cleared, the next tick it's re-found and the cycle repeats.
At first I thought so too, but shouldn't that imply that on_tick is
always too late to affect fast-transfer? Because I
can do the exact opposite and enforce all fast transfers to go to one specific entity regardless of where the player clicks.
Code: Select all
/c
local ship = game.player.surface.find_entities_filtered{name = 'crash-site-spaceship'}[1]
script.on_event(defines.events.on_tick, function(e)
for _, p in pairs(game.players) do p.selected = ship end
end)
Also the demo mod additionally sets selected=nil on
every possible input in the game using linked_game_control custom inputs. And a linked 'fast-transfer' input surely should be right before the actual transfer happens, right?
Code: Select all
for _, input in pairs(const.array_of_inputs) do
script.on_event('on_linked_input_' .. (input:gsub('-','_')), function(e)
pprint('input:'..input)
game.players[e.player_index].selected = nil
end)
end
Re: [1.1.32] fast-transfer ignores LuaPlayer.selected = nil
Posted: Wed May 05, 2021 12:52 pm
by eradicator
Would you please be so nice and confirm that you still consider this NaB after reading my second post/the demo mod? I kinda got the feeling that the on_tick example overshadowed the real issue.
Re: [1.1.32] fast-transfer ignores LuaPlayer.selected = nil
Posted: Wed May 05, 2021 5:44 pm
by Rseding91
eradicator wrote: ↑Wed May 05, 2021 12:52 pm
Would you please be so nice and confirm that you still consider this NaB after reading my second post/the demo mod? I kinda got the feeling that the on_tick example overshadowed the real issue.
I do still consider it not a bug.
Re: [1.1.32] fast-transfer ignores LuaPlayer.selected = nil
Posted: Wed May 05, 2021 5:59 pm
by eradicator
Thanks for checking. I guess my understanding of events is just lacking then. Are linked control custom input events generally raised after the engine raised normal events for them then? [Edit: See post below]
Re: [1.1.32] fast-transfer ignores LuaPlayer.selected = nil
Posted: Wed May 05, 2021 6:39 pm
by eradicator
Ok...so I did another test and now I understand. I did not expect the transfer event to happen
an entire tick after the input.
Code: Select all
/c
local wait = false
script.on_event('on_linked_input_fast_entity_transfer', function(e)
local p = game.players[e.player_index]
game.print(e.tick .. ' Ctrl+LMB on ' .. ( p.selected and p.selected.name or 'nil'))
p.selected = nil
wait = true
end)
script.on_event(defines.events.on_player_fast_transferred, function(e)
local p = game.players[e.player_index]
game.print(e.tick .. ' Fast transfer event on ' .. ( p.selected and p.selected.name or 'nil'))
end)
script.on_event(defines.events.on_tick, function(e)
if wait then
for _, p in pairs(game.players) do
if p.selected == nil then
game.print(e.tick .. ' Selected was nil for ' .. p.name)
else
game.print(e.tick .. ' Selected was '..p.selected.name..' for ' .. p.name)
wait = false
end
end
end
end)
- eventorder.png (26.6 KiB) Viewed 1617 times