function init(self)
	self.sounds_volume = 0
	self.music_volume = 0
end

function final(self)
	-- Add finalization code here
	-- Learn more: https://defold.com/manuals/script/
	-- Remove this function if not needed
end

function update(self, dt)
	--gui.set_position(gui.get_node("sound_bar"), pos)
end

function on_message(self, message_id, message, sender)
	if message_id == hash("sounds_volume") then
		self.sounds_volume = message.sounds_volume
		local sounds_pos = gui.get_position(gui.get_node("sound_bar"))
		gui.set_position(gui.get_node("sound_bar"), vmath.vector3(self.sounds_volume, sounds_pos.y, sounds_pos.z))
	end
	if message_id == hash("music_volume") then
		self.music_volume = message.music_volume
		local music_pos = gui.get_position(gui.get_node("music_bar"))
		gui.set_position(gui.get_node("music_bar"), vmath.vector3(self.music_volume, music_pos.y, music_pos.z))
	end
end

function on_input(self, action_id, action)
	if action_id == hash("touch") and action.pressed then
		if gui.pick_node(gui.get_node("sound_bar"), action.x, action.y) then
			self.dragging_sound = true
		end
		if gui.pick_node(gui.get_node("music_bar"), action.x, action.y) then
			self.dragging_music = true
		end
	elseif action.released then
		self.dragging_sound = false
		self.dragging_music = false
	end
	if self.dragging_sound then
		local sounds_pos = gui.get_position(gui.get_node("sound_bar"))
		if action.x >= 547 and action.x <= 887 then
			gui.set_position(gui.get_node("sound_bar"), vmath.vector3(action.x, sounds_pos.y, sounds_pos.z))
			msg.post("main:/controller#main", "sounds_volume", { sounds_volume = action.x })
		end
	end
	if self.dragging_music then
		local music_pos = gui.get_position(gui.get_node("music_bar"))
		if action.x >= 547 and action.x <= 887 then
			gui.set_position(gui.get_node("music_bar"), vmath.vector3(action.x, music_pos.y, music_pos.z))
			msg.post("main:/controller#main", "music_volume", { music_volume = action.x })
		end
	end
end

function on_reload(self)
	-- Add reload-handling code here
	-- Learn more: https://defold.com/manuals/hot-reload/
	-- Remove this function if not needed
end
