SOLVED Draw Event runs, variable in the event gets turned off, event stops running?

DrScoop

Member
Hi there, I have a few things I'm attempting to do. First I'm trying to use an object to set an array in another object which then "semi-triggers" a dialogue box popping up in the game. here is the code from that part:
GML:
// STEP EVENT OF obj_miniGame
if gameOn == true {
                obj_blackCutOut.visible = true;
                obj_towerPiece.hasPressedX = keyboard_check(global.interact_key) || gamepad_button_check_pressed(0, global.gp_interact_key);   
            } else {
                if dialogFlag == true {
                    dialogLine = 1;
                    obj_combatDialogue.dialogue_on = true;
                    dialogFlag = false;
                } else {
                    // dialogLine = 0;
                }
                
                obj_blackCutOut.visible = false;
            }

            

            // [CENSORED] Custom Dialogue

            // switch statement to allow for many different dialogues during battle.
            
                switch dialogLine {
    
                    case 0:
                    break;
    
                    case 1: {
                        //myText[0] = "And here we are!";
                        //mySpeaker[0] = id;
                        //myText[1] = "Uhh..???"
                        //mySpeaker[1] = obj_player_questioning;
                        //myText[2] = "You look pretty confused! Have you never been in combat before??"
                        //mySpeaker[2] = id;
                        //myNextLine[2] = -1;
                        //myScripts[2] = [change_variable, id, dialogFlag, false];
                        //// TODO: more dialogue
                        //create_dialogue(myText, mySpeaker, myEffects, myTextSpeed, myTypes, myNextLine, myScripts, myTextCol, myEmotion, myEmote)
                        
                        obj_combatDialogue.arr_text = ["Here we are!! Welcome to the COMBAT SYSTEM!"];
                        
                        if !obj_combatDialogue.dialogue_on {
                            myText[0] = "Uhh...?"
                            mySpeaker[0] = obj_player_questioning;
                            myNextLine[0] = -1;
                            myScripts[0] = [change_variable, id, "dialogLine", "2"];
                            create_dialogue(myText, mySpeaker, myEffects, myTextSpeed, myTypes, myNextLine, myScripts, myTextCol, myEmotion, myEmote);
                            dialogFlag = false;
                        }
                        
                        
                    }; break;
                    case 2: {
                        obj_combatDialogue.dialogue_on = true;
                        obj_combatPortrait.sprite_index = spr_[censored]_ovw_hehe;
                        obj_combatDialogue.arr_text = ["You look kinda confused! Have you never been in combat before?"];
                        
                        dialogFlag = false;
                        
                    }; break;
                }
                
            switch statusLine {
    
                default: {
                    statusFlag = false;
                }; break;
    
                case 1: {
                    /* todo: write a text_typer here to type text up in the status area. Set statusTyped to true when the text has fully typed*/
                    statusMsg = "Test message!";

                    // if the text is fully typed and the player pressed x, re-enable ability to select items, commands, and run buttons.
                    if statusTyped == true && (keyboard_check_pressed(global.interact_key) || gamepad_button_check_pressed(0, global.gp_interact_key)) {
                        statusFlag = false;
                    }
                }
            }
So, what the above code does is check if the gameOn var is true, if it isnt it goes to the dialogue code. it checks if we are allowing dialogue yet (by default we are), then it sets the dialogLine to #1 for the switch statement's use. It then turns on dialogue for another object called "obj_combatDialogue.". This object then takes in an array, and prints out the dialog from that array line by line. Here is the code for that:
GML:
// CREATE EVENT OF obj_combatDialogue

typed_letters = 0;
dialogue_on = false;

dialogue1 = "Error! (dialogue 1)";

dialogue2 = "Error! (dialogue 2)";

dialogue3 = "Error! (dialogue 3)";

arr_text = [];
curText = "";

currentLine = 0;
audio_c = 0;

// Set Flags
draw_flag = false;
alarmFlag = false;

curAudioPos = 0;

if arr_text == [] {
    draw_flag = false;
} else {
    dialogue_on = true;
}


// STEP EVENT
lastLine = array_length(arr_text)-1;

// DRAW EVENT
/// @description draw the text in the box

draw_self();

draw_set_font(global.fnt_b);
draw_set_color(c_black)

if dialogue_on == true {
    visible = true;
    // Set current sprite and story text
    if (currentLine <= lastLine) {
        curText = arr_text[currentLine];
        
        // Check if we still are still typing text
        if typed_letters < string_length(curText) {
            typed_letters+=0.25;
            draw_flag = true;
        } else {
            if (keyboard_check(global.interact_key) || gamepad_button_check(0, global.gp_interact_key)) {
                // this is used to clear the text for the next one, only if it isnt the last line
                if currentLine < lastLine {
                
                    typed_letters = 0;
                    draw_flag = false;
                    audio_c = 0;
                    curAudioPos = 0;
                    currentLine += 1;
                }
                
                if currentLine == lastLine {
                    if typed_letters == string_length(curText) {
                        arr_text = [];
                        dialogue_on = false;
                        currentLine = 0;
                    }
                }
            }
        }
    }
    

} else {
    visible = false;
}

// Draw text
if (draw_flag) {
    draw_set_halign(fa_left);
    draw_text_ext(x-6, y+6, string_copy(curText, 0, ceil(typed_letters)), 20, 130);
    // Play audio every new character, might need to be changed
    // Don't go into if statement if curAudioPos is larger than length of curText
    // otherwise will play an extra sound at end no matter what
    if (typed_letters > curAudioPos && curAudioPos < string_length(curText)) {
        curAudioPos++;
        var char =  string_char_at(curText, curAudioPos);
        if (string_pos(" ", char) == 0 && string_pos(".", char) == 0 && string_pos("!", char) == 0 &&
            string_pos(",", char) == 0)
            audio_play_sound(obj_whoIsMyEnemy.enemyVoice, 1, false);
    }
} else {
    draw_text(x, y, "");
}
So, to walk through the above code, obj_miniGame sets arr_text inside obj_combatDialogue. Combat dialogue then realizes that the arr_text variable isnt empty anymore, and it also has "dialogue_on" turned on now. So it then runs through the draw event and draws the text in the dialogue box sprite as it should, going through each line when the interact key is pressed.

Then, we end the combatDialogue code when the lines are done and go back to obj_miniGame, where a different type of dialogue using the fc dialogue system function is used. The issue then arises where after the alternate dialogue box is done being ran (right here it switches the dialogLine variable to #2 so it runs case 2. And i checked, it does run case #2 like it should...), the first dialogue box from obj_combatDialogue box simply doesnt run again right here.

Upon checking in the debugger, i discovered that the DRAW EVENT in obj_combatDialogue just simply refuses to run at this point. Why? Why is the draw event not running when i want to use this dialogue box a second time?
And yes I checked if the object still exists, and the step event is still running in that object. Its literally just the draw event that doesnt wanna run at this point.

I have a feeling my logic with the dialogue_on variable is screwy. Cany ANYONE help me out here?? Thank you.
Please ask if you have any questions about the code or are missing information to help/understand this problem.
 
Check whether the inbuilt visible variable in obj_combatDialogue is false when it's not drawing using the debugger. I can see that you are switching visibility on and off and if the draw event isn't running, it's highly likely it's because obj_combatDialogue is invisible (which means draw events aren't executed at all).

If it isn't visible, you'll have to figure out what part of your code is running that is accidentally setting visibility to false at the wrong point.
 
Last edited:

DrScoop

Member
Check whether the inbuilt visible variable in obj_combatDialogue is false when it's not drawing using the debugger. I can see that you are switching visibility on and off and if the draw event isn't running, it's highly likely it's because obj_combatDialogue is invisible (which means draw events aren't executed at all).

If it isn't visible, you'll have to figure out what part of your code is running that is accidentally setting visibility to false at the wrong point.
Huh, it never occured to be that visibility could be the culprit. I'll look into that when i get back home to my PC. Thank you!
 
Top