Page 1 of 1
[Twinsen]sliders sometimes have wrong values after creation
Posted: Thu Aug 29, 2019 7:41 pm
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")
Re: sliders sometimes have wrong values after creation
Posted: Thu Aug 29, 2019 7:58 pm
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)
Re: [Twinsen]sliders sometimes have wrong values after creation
Posted: Fri Aug 30, 2019 9:58 am
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
Re: [Twinsen]sliders sometimes have wrong values after creation
Posted: Fri Aug 30, 2019 10:12 am
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
Re: [Twinsen]sliders sometimes have wrong values after creation
Posted: Fri Aug 30, 2019 11:04 am
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.