[Twinsen]sliders sometimes have wrong values after creation

This subforum contains all the issues which we already resolved.
Post Reply
User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 400
Joined: Thu Dec 21, 2017 8:02 am
Contact:

[Twinsen]sliders sometimes have wrong values after creation

Post by ownlyme »

im using this code:

Code: Select all

elem.set_slider_minimum_maximum(0,25000)
elem.slider_value = global.entities[entity.unit_number].amount
and it's randomly at max when it's created, even though my textfield next to it says 0
(so the value i'm assigning is 100% correct)
(printing elem.slider_value after the creation also says "0")
Attachments
Screenshot_1.jpg
Screenshot_1.jpg (3.82 KiB) Viewed 2693 times
mods.factorio.com/user/ownlyme
My requests: uiAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance

User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 400
Joined: Thu Dec 21, 2017 8:02 am
Contact:

Re: sliders sometimes have wrong values after creation

Post by ownlyme »

I noticed that it's kinda impossible to reproduce this with a very simple frame, so here's some code that anybody can use to reproduce it:

Code: Select all

/c function fluid_gui(player,entity,mode)
	if player.gui.center["own_market_fluid_"..player.index.."_"..entity.unit_number] then
		player.gui.center["own_market_fluid_"..player.index.."_"..entity.unit_number].destroy()
	end
	local elem

	local recipe_height, recipe_width

	recipe_height = 100
	recipe_width = 405
	
	local gui = player.gui.center.add{type="frame", name= "own_market_fluid_"..player.index.."_"..entity.unit_number, direction="vertical"}
	gui.style.width= recipe_width

	if mode == "buy" then
		local selection_flow = gui.add{type= "flow",name = "selection_flow", direction = "horizontal"}
		elem = selection_flow.add{type= "sprite-button",name = "owm_item_selector",style = "slot_button"}
		elem.style.width = 50
		elem.style.height = 50

		local parameters_flow = selection_flow.add{type= "flow",name = "parameters_flow", direction = "vertical"}
		local x_flow = parameters_flow.add{type= "flow",name = "x_flow"}
		x_flow.style.horizontal_align = "right"
		x_flow.style.width = recipe_width-70
		x_flow.style.top_margin = -2
		x_flow.style.top_padding = -5
		x_flow.style.right_padding = -3
		local temp = x_flow.add{type = "button", name = "own_fluid_sell", style = "icon_back_button", caption = "Sell" }
		temp.style.top_margin = 5
		local temp = x_flow.add{type = "button", name = "own_fluid_buy", style = "confirm_button", caption = "Buy" }
		temp.style.top_margin = 5
		temp.ignored_by_interaction = true
		local temp = x_flow.add{type = "sprite-button", name = "own_fluid_close", sprite = "own_market_close"}
		temp.style.width = 25
		temp.style.height = 25

		local amount_flow = parameters_flow.add{type= "flow",name = "amount_flow"}
		elem = amount_flow.add{type= "label",name = "amount_caption"}
			elem.caption = "Fill up to.."
			elem.style.width = 70
		elem = amount_flow.add{type= "slider",name = "owm_amount_selector"}
			elem.style.top_margin=7
			elem.style.width=recipe_width-210
			elem.set_slider_minimum_maximum(0,25000)
			elem.slider_value = 0
		elem = amount_flow.add{type= "textfield",name = "owm_amount_field"}
		elem.style.width = 60
		elem.style.height = 25
		elem.text = 0
		elem.ignored_by_interaction = true

	else
		local selection_flow = gui.add{type= "flow",name = "selection_flow", direction = "horizontal"}

		local parameters_flow = selection_flow.add{type= "flow",name = "parameters_flow", direction = "vertical"}
		local x_flow = parameters_flow.add{type= "flow",name = "x_flow"}
		x_flow.style.horizontal_align = "right"
		x_flow.style.width = recipe_width-16
		x_flow.style.top_margin = -2
		x_flow.style.top_padding = -5
		x_flow.style.right_padding = -3
		local temp = x_flow.add{type = "button", name = "own_fluid_sell", style = "red_back_button", caption = "Sell" }
		temp.style.top_margin = 5
		temp.ignored_by_interaction = true
		local temp = x_flow.add{type = "button", name = "own_fluid_buy", style = "forward_button", caption = "Buy" }
		temp.style.top_margin = 5
		local temp = x_flow.add{type = "sprite-button", name = "own_fluid_close", sprite = "own_market_close"}
		temp.style.width = 25
		temp.style.height = 25
	
	
	end
	
	
	player.opened = gui

end

Code: Select all

/c script.on_nth_tick(10, function() fluid_gui(game.players[1], game.players[1].character, "buy") end)
mods.factorio.com/user/ownlyme
My requests: uiAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance

Twinsen
Factorio Staff
Factorio Staff
Posts: 1330
Joined: Tue Sep 23, 2014 7:10 am
Contact:

Re: [Twinsen]sliders sometimes have wrong values after creation

Post by Twinsen »

Your code was returning some errors. I fixed it, but running it created the marker in the correct position.
But I looked at the game code and it's probably due to some uninitialized value. So I most probably fixed it for Version: 0.17.67

User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 400
Joined: Thu Dec 21, 2017 8:02 am
Contact:

Re: [Twinsen]sliders sometimes have wrong values after creation

Post by ownlyme »

what errors do you mean? the closing sprite i forgot to remove?
or that i declared local variables multiple times?
also it doesn't happen every time, that's why i included an nth tick event, you should actually see it after 5-10 seconds max
mods.factorio.com/user/ownlyme
My requests: uiAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance

Twinsen
Factorio Staff
Factorio Staff
Posts: 1330
Joined: Tue Sep 23, 2014 7:10 am
Contact:

Re: [Twinsen]sliders sometimes have wrong values after creation

Post by Twinsen »

The closing sprite was causing the error, yeah.
I tested with the nth tick and it doesn't seem to happen but please also test when Version: 0.17.67 is released if you can.

Post Reply

Return to “Resolved Problems and Bugs”