GML [SOLVED] INI Values Not Being Drawn Correctly

witches

Member
hello all, first time posting.
I'm running into issues when relaying ini values to the draw event of my menu object. And the strangest part is that it is only 4, 5, 6, and 9.

I have a menu system set where I directly write into the ini file and have that value set for the audio_group_set_gain and audio_master_gain functions.
The results are interesting... Heres some code:

step event:
Code:
 //-----Set Options
selections = [    "Back",
                         "Master",
                         "Music",
                         "Sound Effects"];

ini_open("options.ini");

var    sfx_vol         = ini_read_real("audio","sound",1.0);
var    music_vol    = ini_read_real("audio","music",1.0);
var    master_vol  = ini_read_real("audio","master",1.0);
ini_close();

//-----Set Option Values
panel_options = [    "",
                    string(master_vol*10),
                    string(music_vol*10),
                    string(sfx_vol*10)];
~~~
var select;
if key_left
{
    switch(current_select)
    {
        case 1:        select = "master";
                            break;   
        case 2:        select = "music";
                            break;
        case 3:        select = "sound";
                            break;
    }
    scrAudioGain(select,-0.1);
    menu_xspeed = -scroll;
}

if key_right
{
    switch(current_select)
    {
        case 1:        select = "master";
                            break;   
        case 2:        select = "music";
                            break;
        case 3:        select = "sound";
                            break;
    }
    scrAudioGain(select,0.1);
    menu_xspeed = scroll;
}
~~~
scrAudioGain:
Code:
ini_open("options.ini");

var add = argument1;

//---Get ini Values
var sfx_vol        = ini_read_real("audio","sound",1.0);
var music_vol    = ini_read_real("audio","music",1.0);
var master_vol    = ini_read_real("audio","master",1.0);

switch(argument0)
{
    case "master":    if (master_vol +add > 1) or (master_vol +add < 0) break;
                    audio_master_gain(master_vol+add);
                    ini_write_real("audio", argument0, master_vol+add);
                    break;
    
    case "sound":    if (sfx_vol +add > 1) or (sfx_vol +add < 0) break;
                    audio_group_set_gain(audio_sfx, sfx_vol+add, 0);
                    ini_write_real("audio", argument0, sfx_vol+add);
                    break;
    
    case "music":    if (music_vol +add > 1) or (music_vol +add < 0) break;
                    audio_group_set_gain(audio_music, music_vol+add, 0);
                    ini_write_real("audio", argument0, music_vol+add);
                    break;
}

ini_close();
and Draw GUI:
Code:
for(var i=0; i < array_length_1d(selections); i++)
{
    if (i == current_select) var co = 1;
    else co = 0.4;
    var w = c_white;
    var t_pos_x = center_x + menu_xspeed,
          t_pos_y = (y_start + menu_yspeed) + i*string_height(global.stringheight)+32,
          t_buff  = 32;

    //--left
    draw_set_halign(fa_right);
    draw_text_color(t_pos_x -t_buff, t_pos_y, selections[i], w,w,w,w,co);

    //--right
    draw_set_halign(fa_left);
    draw_text_color(t_pos_x +t_buff, t_pos_y, panel_options[i], w,w,w,w,co);

~~~
}
heres some gifs of what it looks like:
debug_view.gif
this post wont let me upload the game gif so i linked an imgur album with both
imgur album: https://imgur.com/a/BBFsrf0

Any ideas on what could be going on? Any sort of help would be greatly appreciated.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
I think the issue could well be that you are potentially opening and closing the INI file every step, which could be clogging the file IO and so "skipping" values? In general, you want to keep file access to an absolute minimum, and most menus/options only save the values when the user exits the options screen or section. I would recommend refactoring so that you only load the values when the section is opened by the user and only save when the section is closed. If things still don't work after that then you at least know it's not a file IO issue... :)
 

witches

Member
I think the issue could well be that you are potentially opening and closing the INI file every step, which could be clogging the file IO and so "skipping" values? In general, you want to keep file access to an absolute minimum, and most menus/options only save the values when the user exits the options screen or section. I would recommend refactoring so that you only load the values when the section is opened by the user and only save when the section is closed. If things still don't work after that then you at least know it's not a file IO issue... :)
I've created variable that holds display values edited when the audio panel is open from the ini file then writes the new values to the ini when the panel closes, effectively only opening the ini file when entering the audio panel and closing the panel. However, this new method is yielding the same results.... there has to be something wrong with the draw event of how my panel_options array holds data.... becuase when i multiply these values by 10 to give me integers to display im getting weird values like "7.00" and "0.00" drawn instead.
Any thoughts? (also thank you for the suggestion)
 
T

Taddio

Guest
there has to be something wrong with the draw event of how my panel_options array holds data.... becuase when i multiply these values by 10 to give me integers to display im getting weird values like "7.00" and "0.00" drawn instead.
Any thoughts? (also thank you for the suggestion)
I don't know why, but if you save an integer to an ini, and then open it and have a look inside, it will display 1.0000000 instead of 1. Maybe that's what causing your display issue. Try to mess around with
string_format(val, tot, dec);
to make the display as you want it to be
 

witches

Member
I don't know why, but if you save an integer to an ini, and then open it and have a look inside, it will display 1.0000000 instead of 1. Maybe that's what causing your display issue. Try to mess around with
string_format(val, tot, dec);
to make the display as you want it to be
This helps tremendously! The values mentioned that I have issues displaying only show as blank spaces but now it is only showing integers which is a huge step! Thank you for the reply this function is a godsend.
 

witches

Member
[SOLUTION] The font used for the menu drawing omitted 4, 5, 6, and 9 in its range for numbers. I'm not sure how this happened or how I overlooked that, but it makes things alot simpler now knowing what was wrong and is something to keep track of in the future
 
Top