[2.0.60] Bad undo stack order in on_built callbacks of entity placement vs blueprint placement

This subforum contains all the issues which we already resolved.
Loup&Snoop
Inserter
Inserter
Posts: 43
Joined: Wed Dec 04, 2024 4:33 am
Contact:

[2.0.60] Bad undo stack order in on_built callbacks of entity placement vs blueprint placement

Post by Loup&Snoop »

The Reproduction and Bug
1) Listen to an on_built_entity event with the following in a control.lua:

Code: Select all

script.on_event(defines.events.on_built_entity, function(event)
	local player_index = event.player_index
	game.print("Before: " .. tostring(game.players[player_index].undo_redo_stack.get_undo_item_count()))
        event.entity.rotate{by_player=player_index}
        game.print("After: " .. tostring(game.players[player_index].undo_redo_stack.get_undo_item_count()))
end)
I recommend printing the size of the undo stack to see what is going on:
/c game.print("Current undo stack size: " .. tostring(game.players[1].undo_redo_stack.get_undo_item_count()))

Look! A super handy control.lua file for testing! Better download it before it has a chance to run away:
control.lua
(592 Bytes) Downloaded 17 times

With this code in (assuming you start with nothing in the undo stack):

Case 1:
-Place an inserter via cursor. It gets rotated when you place it.
-Code will print: Before: 0, After: 1. End with an undo stack size of 2.
-Undo stack now has the placement of the inserter on top, and the rotation on the bottom.
-Press undo once => Inserter destruction
-Press undo again => the command fizzles and does nothing

Case 2:
-Place a blueprint that is just an inserter. It gets rotated when you place it.
-Code will print: Before: 1, After: 2. End with an undo stack size of 2.
-Undo stack now has the rotation on the top, and the entity placement on the bottom.
-Press undo once => Inserter gets un-rotated
-Press undo again => Inserter destruction
Expected Behavior
I expect the undo stack to not depend on whether I'm placing things via blueprint or normal entity placement, when scripts are doing things in on_built_entity callbacks.
Rseding91
Factorio Staff
Factorio Staff
Posts: 16024
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [2.0.60] Bad undo stack order in on_built callbacks of entity placement vs blueprint placement

Post by Rseding91 »

Thanks for the report. This is now fixed for the next release.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Resolved Problems and Bugs”