[Solved]Minimap interacts incorrectly with the slider

Place to get help with not working mods / modding interface.
User avatar
WIZ4
Fast Inserter
Fast Inserter
Posts: 209
Joined: Thu Apr 07, 2016 1:36 pm
Contact:

[Solved]Minimap interacts incorrectly with the slider

Post by WIZ4 »

Hi, I can’t sync the slider value with the minimap zoom. The values of the slider and the zoom of the minimap are the same. But as soon as I start using the slider to zoom in, the zoom suddenly changes dramatically. What is the reason?
slider.gif
slider.gif (746.26 KiB) Viewed 2743 times

Code: Select all

function slider_zoom()
	local frame = game.player.gui.center.add{ type = "frame", name = "frame", direction="vertical"} 
	frame.add{type = "minimap", name = "minimap", position = {0,0},surface_index=game.surfaces.nauvis.index,zoom=0.50}
	frame.add{type="slider", name="slider",orientation=horizontal, minimum_value=0.49,maximum_value=0.50,value=0.50}	
	frame.add{type = "label", name = "slider_value_number", caption = "slider value = "..frame.slider.slider_value}
	frame.add{type = "label", name = "minimap_zoom", caption = "minimap zoom = "..frame.minimap.zoom}
end

Code: Select all

script.on_event(defines.events.on_gui_value_changed, function(event)
		if name == "slider" then 
		player.gui.center.frame.minimap.zoom = event.element.slider_value
		player.gui.center.frame.slider_value_number.caption = "slider value = "..event.element.slider_value
		player.gui.center.frame.minimap_zoom.caption = "minimap zoom = "..player.gui.center.frame.minimap.zoom
	end
end)
Last edited by WIZ4 on Thu Nov 22, 2018 10:10 pm, edited 1 time in total.
My native language is russian. Sorry if my messages are difficult to read.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Minimap interacts incorrectly with the slider

Post by eradicator »

Code: Select all

	frame.add{type = "minimap", name = "minimap", position = {0,0},surface_index=game.surfaces.nauvis.index,zoom=0.50}
add() does not take zoom as an argument. You have to change the zoom level after creation. Otherwise the map is created with standard value of..something like 0.15? And when you use the slider it gets set to 0.5 for the first time.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
User avatar
WIZ4
Fast Inserter
Fast Inserter
Posts: 209
Joined: Thu Apr 07, 2016 1:36 pm
Contact:

Re: Minimap interacts incorrectly with the slider

Post by WIZ4 »

eradicator wrote: Thu Nov 22, 2018 9:59 pm

Code: Select all

	frame.add{type = "minimap", name = "minimap", position = {0,0},surface_index=game.surfaces.nauvis.index,zoom=0.50}
add() does not take zoom as an argument. You have to change the zoom level after creation. Otherwise the map is created with standard value of..something like 0.15? And when you use the slider it gets set to 0.5 for the first time.
It worked, thanks. So is this a bug or should it be?
My native language is russian. Sorry if my messages are difficult to read.
Bilka
Factorio Staff
Factorio Staff
Posts: 3470
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Minimap interacts incorrectly with the slider

Post by Bilka »

WIZ4 wrote: Thu Nov 22, 2018 10:08 pm So is this a bug or should it be?
Does the documentation state that it should work? No.









conclusion
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Minimap interacts incorrectly with the slider

Post by eradicator »

Bilka wrote: Thu Nov 22, 2018 11:08 pm
WIZ4 wrote: Thu Nov 22, 2018 10:08 pm So is this a bug or should it be?
Does the documentation state that it should work? No.
After further investigation:
Both 0.16 and 0.17 preview doc state that it should work.
It actually "works" but is broken.
The bug is as follows:
add() sets the r/w "zoom" parameter for the minimap gui element to zoom*1, i.e. if you read map.zoom right after creation it will appear to have worked, but the value that is actually applied to the minimap is zoom/32. Can be easily verified by setting the map to it's own zoom value:

Code: Select all


/c c = game.player.gui.center

/c c.clear() c.add{type='minimap',name='map'}

/c c.map.zoom = c.map.zoom --should not change anything but does!
zoom32.jpg
zoom32.jpg (198.4 KiB) Viewed 2699 times
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Bilka
Factorio Staff
Factorio Staff
Posts: 3470
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Minimap interacts incorrectly with the slider

Post by Bilka »

eradicator wrote: Fri Nov 23, 2018 12:40 pm
Bilka wrote: Thu Nov 22, 2018 11:08 pm
WIZ4 wrote: Thu Nov 22, 2018 10:08 pm So is this a bug or should it be?
Does the documentation state that it should work? No.
After further investigation:
Both 0.16 and 0.17 preview doc state that it should work.
Derp, I looked at the wrong thing...
eradicator wrote: Fri Nov 23, 2018 12:40 pm It actually "works" but is broken.
The bug is as follows:
... snip ...
I can confirm this. The issue seems to be that when the minimap is created, the scale of what is rendered is set to zoom / 32. But, zoom is still 0.75, and when you set it normally, the division is not done.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Minimap interacts incorrectly with the slider

Post by eradicator »

Bilka wrote: Fri Nov 23, 2018 1:04 pm I can confirm this. The issue seems to be that when the minimap is created, the scale of what is rendered is set to zoom / 32. But, zoom is still 0.75, and when you set it normally, the division is not done.
So who's gonna post the bug report? Or are you gonna fix it without one :D.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Bilka
Factorio Staff
Factorio Staff
Posts: 3470
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Minimap interacts incorrectly with the slider

Post by Bilka »

eradicator wrote: Fri Nov 23, 2018 1:36 pm So who's gonna post the bug report? Or are you gonna fix it without one :D.
I fixed it without one :)
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
User avatar
WIZ4
Fast Inserter
Fast Inserter
Posts: 209
Joined: Thu Apr 07, 2016 1:36 pm
Contact:

Re: [Solved]Minimap interacts incorrectly with the slider

Post by WIZ4 »

Wow! Well done, guys!
My native language is russian. Sorry if my messages are difficult to read.
Post Reply

Return to “Modding help”