0 votes

Hello,
I get done together a script for a change resolution, but for some reason,
when I change res and confirm by button, nothing changes....where's my mistake? Thank you very much
.....default res I have 800x480
.....func _on_Ok_button_pressed():....this is confirm button func to change res
but does not work.

extends Control

var settings = {"resolution_x":800,"resolution_y":480,"music":true,
"music_volume":1.0,"sound":true,"sound_volume":1.0}

var res = Vector2(800,480)
var sound = true
var sound_volume = 1.0
var music = true
var music_volume = 1.0

func _ready():
    set_process(true)
#------------------------------------------------------------------------------
# resolution-------------------------------------------------------------------
func set_res_x(value):
    res.x = value
#------------------------------------
func set_res_y(value):
    res.y = value
#------------------------------------
# resize resolution-------------------------------------------------------------
func _resize():
    res = OS.get_video_mode_size()
    settings["resolution_x"] = res.x
    settings["resolution_y"] = res.y
    get_node("SpinBoxX").set_value(res.x)
    get_node("SpinBoxY").set_value(res.y)
#default resolution------------------------------------------------------------
func default_settings():
    settings["resolution_x"] = OS.get_screen_size().x
    settings["resolution_y"] = OS.get_screen_size().y
# options cancel---------------------------------------------------------------
func options_cancel():
    res = Vector2(settings["resolution_x"],settings["resolution_y"])
#   sound = settings["sound"]
#   sound_volume = settings["sound_volume"]
#   music = settings["music"]
#   music_volume = settings["music_volume"]
    get_node("SpinBoxX").set_value(res.x)
    get_node("SpinBoxY").set_value(res.y)
#   get_node("CheckBox").set_pressed(sound)
#   get_node("SpinBoxV").set_value(sound_volume*100)
#   get_node("CheckBox").set_pressed(music)
#   get_node("SpinBoxV").set_value(music_volume*100)

    OS.set_window_size(res)
#   OS.set_video_mode(res,true)
#   AudioServer.set_fx_global_volume_scale(sound_volume*sound)
#   AudioServer.set_stream_global_volume_scale(music_volume*music)
# options confirm-------------------------------------------------------------
func options_confirm():
    settings["resolution_x"] = res.x
    settings["resolution_y"] = res.y
#   settings["sound"] = sound
#   settings["sound_volume"] = sound_volume
#   settings["music"] = music
#   settings["music_volume"] = music_volume

    OS.set_window_size(res)
#   OS.set_video_mode(res,true)
#   AudioServer.set_fx_global_volume_scale(sound_volume*sound)
#   AudioServer.set_stream_global_volume_scale(music_volume*music)
    options_cancel()
# sound music func---------------------------------------------------
func enable_sound(pressed):
    sound = pressed
#--------------------------------------------------------------------
func set_sound_volume(value):
    sound_volume = value/100.0
#--------------------------------------------------------------------
func enable_music(pressed):
    music = pressed
#--------------------------------------------------------------------
func set_music_volume(value):
    music_volume = value/100.0
#--------------------------------------------------------------------
func _on_Ok_button_pressed():
    OS.set_window_size(res)
    options_confirm()
#--------------------------------------------------------------------
func _on_back_to_level_menu_pressed():
    get_tree().change_scene("res://scenes/select_track.tscn")
#--------------------------------------------------------------------

enter image description here

in Engine by (450 points)

2 Answers

0 votes
Best answer

This works...just now I can change res.
....I was have some code (value,.etc) missing but I get it.
.....but this script needs some clean up I think :-)

extends Control

var settings = {"resolution_x":800,"resolution_y":480,"fullscreen":false,"music":true,
"music_volume":1.0,"sound":true,"sound_volume":1.0}



var res = Vector2()
var sound = true
var sound_volume = 1.0
var music = true
var music_volume = 1.0
var fullscreen = false
var value
var SpinBoxX 
var SpinBoxY


func _ready():
    set_process(true)
    set_process_input(true)
    SpinBoxX = get_node("SpinBoxX")
    SpinBoxY = get_node("SpinBoxY")
#------------------------------------------------------------------------------
# resolution-------------------------------------------------------------------
func set_res_x(value):
    res.x = SpinBoxX.get_value()
#------------------------------------
func set_res_y(value):
    res.y = SpinBoxY.get_value()
#------------------------------------
# fullscreen ------------------------------------------------------------------
func set_fullscreen(pressed):
    fullscreen = pressed
# resize resolution-------------------------------------------------------------
func _resize():
    res = OS.get_video_mode_size()
    settings["resolution_x"] = res.x
    settings["resolution_y"] = res.y
    SpinBoxX.set_value(res.x)
    SpinBoxY.set_value(res.y)
#default resolution------------------------------------------------------------
func default_res():
    settings["resolution_x"] = OS.get_screen_size().x
    settings["resolution_y"] = OS.get_screen_size().y
    settings["fullscreen"] = true
# options cancel---------------------------------------------------------------
func options_res():
    res = Vector2(settings["resolution_x"],settings["resolution_y"])
    fullscreen = settings["fullscreen"]
#   sound = settings["sound"]
#   sound_volume = settings["sound_volume"]
#   music = settings["music"]
#   music_volume = settings["music_volume"]
    SpinBoxX.set_value(res.x)
    SpinBoxY.set_value(res.y)
#   get_node("CheckBox").set_pressed(sound)
#   get_node("SpinBoxV").set_value(sound_volume*100)
#   get_node("CheckBox").set_pressed(music)
#   get_node("SpinBoxV").set_value(music_volume*100)

    OS.set_window_size(res)
    OS.set_video_mode(res,fullscreen,true)
    OS.set_window_fullscreen(fullscreen)
#   AudioServer.set_fx_global_volume_scale(sound_volume*sound)
#   AudioServer.set_stream_global_volume_scale(music_volume*music)
# options confirm-------------------------------------------------------------
func confirm_res():
    settings["resolution_x"] = res.x
    settings["resolution_y"] = res.y
    settings["fullscreen"] = fullscreen
#   settings["sound"] = sound
#   settings["sound_volume"] = sound_volume
#   settings["music"] = music
#   settings["music_volume"] = music_volume

    OS.set_window_size(res)
    OS.set_video_mode(res,fullscreen,true)
    OS.set_window_fullscreen(fullscreen)
#   AudioServer.set_fx_global_volume_scale(sound_volume*sound)
#   AudioServer.set_stream_global_volume_scale(music_volume*music)
# sound music func---------------------------------------------------
func enable_sound(pressed):
    sound = pressed
#--------------------------------------------------------------------
func set_sound_volume(value):
    sound_volume = value/100.0
#--------------------------------------------------------------------
func enable_music(pressed):
    music = pressed
#--------------------------------------------------------------------
func set_music_volume(value):
    music_volume = value/100.0
#--------------------------------------------------------------------
func _on_confirm_pressed():
    set_res_x(value)
    set_res_y(value)
    OS.set_window_size(res)
#--------------------------------------------------------------------
func _on_back_to_level_menu_pressed():
    get_tree().change_scene("res://scenes/select_track.tscn")
#--------------------------------------------------------------------
by (450 points)
0 votes

May be need restart scene

by (208 points)

Thanks....but not...restart do'nt solve this
I was have some missing func. on press confirm button and get.value connections
.....restart scene has nothing to do with it, this script is for change in game resolution....
just classical stuff in games.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.