I am still getting this issue:
viewtopic.php?t=82492
but only when I call
player.cancel_crafting() from a mod
this bug was reported for my better crafting queue mod here
https://mods.factorio.com/mod/better-cr ... b6195d4897
			
							[.18.34] Recipe categories scroll reset
- micromario
 - Fast Inserter

 - Posts: 118
 - Joined: Thu Apr 05, 2018 11:53 am
 - Contact:
 
[.18.34] Recipe categories scroll reset
- Attachments
 - 
			
		
		
				
- factorio-current.log
 - (141.39 KiB) Downloaded 149 times
 
 
Re: [.18.34] Recipe categories scroll reset
I can't reproduce. When I use cancel_crafting from the console it doesn't reset the scroll bar for me.
What else are you doing API wise? From what I can see, the only time when it will scroll up is if a recipe is enabled/disabled or the active group tab is changed.
			
			
									
									What else are you doing API wise? From what I can see, the only time when it will scroll up is if a recipe is enabled/disabled or the active group tab is changed.
If you want to get ahold of me I'm almost always on Discord.
						- micromario
 - Fast Inserter

 - Posts: 118
 - Joined: Thu Apr 05, 2018 11:53 am
 - Contact:
 
Re: [.18.34] Recipe categories scroll reset
Code: Select all
local function score(recipe)
	local recipe_prototype = game.recipe_prototypes[recipe.recipe]
	local result = game.item_prototypes[recipe_prototype.products[1].name]
	local score = 10
	if result.attack_parameters then -- guns
		score = 13000
	elseif result.magazine_size then -- bullets
		score = 10000
	elseif result.resistances then -- armor
		score = 7000
	elseif result.speed then -- repair kit and mining tools
		score = 3000
	--[[
	elseif result.fuel_category then -- solid fuel
		score = 1800
	--]]
	elseif result.capsule_action then -- capsules
		score = 1000
	elseif result.place_result then -- buildings
		score = 500
	elseif result.type == 'tool' then -- science packs
		score = 320
	elseif result.place_as_tile_result then -- tiles
		score = 80
	elseif result.module_effects then -- modules
		score = 1
	end
	
	return score / math.sqrt(recipe_prototype.energy) / recipe.count
end
script.on_event(defines.events.on_pre_player_crafted_item, function(event)
	global.busy = global.busy or {}
	local busy = global.busy
	local pid = event.player_index
	
	if busy[pid] then return end
	local player = game.players[pid]
	if player.crafting_queue_size == 1 then return end
	
	local inventory_size = player.character_inventory_slots_bonus
	player.character_inventory_slots_bonus = 10 * inventory_size + 2000
	local current = player.crafting_queue[#player.crafting_queue]
	local current_score = score(current)
	
	player.cancel_crafting({index=current.index, count=current.count})
	
	local cache = {}
	while player.crafting_queue do
		local this = player.crafting_queue[#player.crafting_queue]
		if this.recipe == current.recipe or score(this) > current_score then break end
		cache[#cache + 1] = this
		player.cancel_crafting({index=this.index, count=this.count})
	end
	
	busy[pid] = true
	
	player.begin_crafting{count=current.count, recipe=current.recipe}
	for i = #cache, 1, -1 do
		local v = cache[i]
		player.begin_crafting({count = v.count, recipe = v.recipe})
	end
	player.character_inventory_slots_bonus = inventory_size
	busy[pid] = nil
end)The API functions I'm using are
game.players[]
game.recipe_prototypes[]
game.item_prototypes[]
LuaPlayer.cancel_crafting
LuaPlayer.begin_crafting
LuaPlayer.character_inventory_slots_bonus =
LuaPlayer.crafting_queue[]
Now that I think about it its very possible that setting inventory size would reset scroll
Re: [.18.34] Recipe categories scroll reset
Yes, changing the inventory size reloads the entire GUI which as a side effect resets the scroll location. That's just how it has to work.
			
			
									
									If you want to get ahold of me I'm almost always on Discord.
						- micromario
 - Fast Inserter

 - Posts: 118
 - Joined: Thu Apr 05, 2018 11:53 am
 - Contact:
 
Re: [.18.34] Recipe categories scroll reset
Thank you for letting me know. I'll try to find a solution that does not involve resizing the inventory
			
			
									
									
						