help with start menu array

beanzlol

Member
I am new to game maker. I am trying to create a start menu based on these tutorials.
the second tutorial appears to account for the recent array changes. They work well mostly but in menu case 2 (options) it refuses to take me to the corresponding options sub menu. It instead it uses either case 1 (load) or case 3(exit game) depending on the direction I scroll into case 2.
I keep looking for errors but I cannot find any. I feel like I am messing up something very simple.
Here is my code. Thank y'all for your help.

version IDE v2.3.5.589

obj_techincal_Page
event: create

GML:
/// variables

#macro main            0
#macro settings        1


Tmenu[main][0] = "SAVE";
Tmenu[main][1] = "LOAD";
Tmenu[main][2] = "OPTIONS";
Tmenu[main][3] = "EXIT GAME";

Tmenu[settings][0] = "GRAPHICS"
Tmenu[settings][1] = "AUDIO"
Tmenu[settings][2] = "CONTROLS"
Tmenu[settings][3] = "BACK"

Tindex = 0;
TSub_Menu = main;

obj_techincal_Page
event: step
GML:
///// Rindex

var _up = keyboard_check_pressed(vk_up);
var _down = keyboard_check_pressed(vk_down);
var _select = keyboard_check_pressed(vk_enter);


var _move = _down - _up;
if _move != 0
{  
    Tindex += _move;

    var _size = array_length(Tmenu[TSub_Menu]);
    if Tindex < 0 Tindex = _size -1;
    else if Tindex >= _size Tindex = 0;
}

//// select things to happen

if _select {
    switch(TSub_Menu) {
        case main:// main menu
            switch(Tindex) {
                case 0:///save
                room_goto(room_save);
                break;
                case 1:///load
                room_goto(room_load);
                break;
                case 2:
                TSub_Menu = settings;
                Tindex = 0;
                break;
                case 3:    ///exit game
                game_end()
                break;
}
break;
        case settings:
        switch(Tindex) {
            case 0:///GRAPCHICS
            room_goto(room_save);
            break;
            case 1:///AUDIO
            room_goto(room_load);
            break;
            case 2:///CONTROLS
            room_goto(room_controls);
            break;
            case 3:    ///BACK
            TSub_Menu = main;
            Tindex = 0;
            break;
}
break;
}
}

obj_techincal_Page
event: draw

GML:
/// draw self
draw_self()

/// draw Roster menu options
draw_set_halign(fa_center)
draw_set_font(Font1)

var _gap = 20;



for (var i = 0; i < array_length(Tmenu[TSub_Menu]); ++i)
{
    draw_set_color(c_black);
    if i == Tindex draw_set_color(c_red);
    draw_text(obj_Protagonist.x + 16, obj_Protagonist.y - 32 +_gap * i,Tmenu[TSub_Menu][i]);
}
 

Nidoking

Member
I don't know if that is the solution but why do you have break; after the closing of the switch ?
Try removing those 2.
It's a nested switch statement. The indentations aren't THAT bad.

For this problem, you want to watch the values of the variables controlling the menu selections in the debugger. See what happens when you select the OPTIONS option and that will narrow down whether the problem is that the variables are set incorrectly, or something is using them to do the wrong thing. Work from there.
 

beanzlol

Member
I don't know if that is the solution but why do you have break; after the closing of the switch ?
Try removing those 2.
It's a nested switch statement. The indentations aren't THAT bad.

For this problem, you want to watch the values of the variables controlling the menu selections in the debugger. See what happens when you select the OPTIONS option and that will narrow down whether the problem is that the variables are set incorrectly, or something is using them to do the wrong thing. Work from there.

thanks y'all, I've never used the debugger before. I will try and figure it out.
 

Slyddar

Member
There is nothing wrong with your code. After spending 10 minutes looking at it, unable to find an error, I copied and pasted it into a project and it runs perfectly. I did remove the obj_Protagonist references, the font reference and changed the colours, but it works fine. Your problem lies elsewhere, not in the code you have posted.
 

beanzlol

Member
There is nothing wrong with your code. After spending 10 minutes looking at it, unable to find an error, I copied and pasted it into a project and it runs perfectly. I did remove the obj_Protagonist references, the font reference and changed the colours, but it works fine. Your problem lies elsewhere, not in the code you have posted.
haha hey thanks teacher. yeah im trying to figure out the de bugger im hoping that will show me the way
 

beanzlol

Member
I am still having trouble with this issue. I am trying to figure out the debugger, when I run it, it tells me that the highlighted instance has the correct variable value according to the array. It still selects a differrent choice when I hit enter though. Am I loooking at the wrong thing? What is it I am looking for?
 

Nidoking

Member
It still selects a differrent choice when I hit enter though.
Then you need to look at what turns the value of that variable into a choice. That's where the problem is. Now you have to figure out why that isn't working the way you want. Go through it line by line, character by character. And guess what? The debugger can help you with that too. Step through it and look at the variable values until you find one that doesn't match what you think it should be. Then figure out how it got that value. Then fix it.
 

beanzlol

Member
Then you need to look at what turns the value of that variable into a choice. That's where the problem is. Now you have to figure out why that isn't working the way you want. Go through it line by line, character by character. And guess what? The debugger can help you with that too. Step through it and look at the variable values until you find one that doesn't match what you think it should be. Then figure out how it got that value. Then fix it.

Got it, I think I understand. Ill keep playing with it, thanks again.
 
Top