• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Change fonts if selected

L

Latch

Guest
Hi all, Ive recently come back to GM and I am incredibly rusty. I have my old code for my game which I am in the process of recreating to get me back to scratch, however, I cant seem to figure this part out:

I am trying to have the font change if the option is selected, the code looks like this:

Code:
for(var i=0;i<maxselect;i++)
{
    if selected = i
    {
        draw_set_font(font2);             
    }
        //When the text is not selected
    else {draw_set_font(font1);}
}

if room = rm_main
{
    draw_text (192,416,"Start Game")
    draw_text (192,416+64,"Options")
    draw_text (192,416+128,"Exit Game")
}
}
But this changes all the fonts and not just the one that is selected, what am I doing wrong?
 

FrostyCat

Redemption Seeker
You just shuffled paint buckets around for short while, then painted a wall with the last one you handled. Would you be surprised if your wall turned out to be only one colour?

Put your options in an array beforehand:
Code:
options_rm_main[0] = "Start Game";
options_rm_main[1] = "Options";
options_rm_main[2] = "Exit Game";
Then incorporate that into your loop:
Code:
for(var i = 0; i < maxselect; i++)
{
    if (selected == i)
    {
        draw_set_font(font2);            
    }
    else
    {
        draw_set_font(font1);
    }
    draw_text(192, 416+64*i, options_rm_main[i]);
}
 

TailBit

Member
The text have to be drawn between each font change
Code:
if room = rm_main
{
    var text = ["Start Game","Options","Exit Game"];

    for(var i=0;i<maxselect;i++)
    {

       if selected = i {
           draw_set_font(font2);
       }else{
           draw_set_font(font1);
       }

       draw_text (192,416,text[i])
    }

}
or do it with the font instead:
Code:
if room = rm_main
{
    var i=0;
    var f = [font1,font2];

    draw_set_font(f[i++=selected]);
    draw_text (192,416,"Start Game")

    draw_set_font(f[i++=selected]);
    draw_text (192,416+64,"Options")

    draw_set_font(f[i++=selected]);
    draw_text (192,416+128,"Exit Game")
}
 
Top