1. Hey! Guest! The 31st GMC Jam will take place between Nov 16th, 12:00 UTC (Friday noon) and Nov 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

[SOLVED]At end of dialogue, do something

Discussion in 'Programming' started by OblivionSkull21, Jun 13, 2018.

  1. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    139
    I've been trying all day to get my dialogue system to work properly. The system works in the sense that I can only press SPACE to go to the next line of text if the text has finished displaying (typewriter-style). I'm wanting an alarm to be set once the player reaches a certain line of text (the last one). The alarm will take them to a different room. So, instead of pressing SPACE again to close out the text, the alarm will be so short that it takes the player by surprise.

    I use several scripts in this system...
    scr_add_dialogue_line:
    Code:
    // @description Add Dialogue to our text array;
    // @param sprite_index
    // @param string text
    
    dialogue[convoDialogueCount, 0] = argument0; //sprite index (avatar)
    dialogue[convoDialogueCount++, 1] = argument1; //text
    
    scr_DisplayConvoText (this is the main one I've been working with):
    Code:
    count = 0; //for timing of events
    
    if (currCharIndex < string_length(dialogue[convoIndex, 1])+1) //checks to see if line hasn't finished
    {
       spriteToDisplay = dialogue[convoIndex, 0];
       currChar = string_char_at(dialogue[convoIndex, 1], currCharIndex);
       stringToDisplay += currChar;
       currCharIndex += 1;
    
    }else{
    
        if (keyboard_check_pressed(vk_space)) //go to next line
        {
        convoIndex++; //works
        stringToDisplay = ""; //works
        currCharIndex = 1; //works
        count = count + 1; //doesn't work
        
            if (convoIndex == convoDialogueCount)
            {
            active = false;
           count = 0; // doesn't work
            }
        }
    }
    
     if (keyboard_check_pressed(ord('Z'))) //skip text/go to next line
        {
        convoIndex++;
        stringToDisplay = "";
        currCharIndex = 1;
        
            if (convoIndex == convoDialogueCount)
            {
            active = false;
            
            }
    }
    scr_initialize_dialogue:
    Code:
    for (i = 0; i < 20; i++)
    {
        dialogue[i, 0] = -1; // sprite index
        dialogue[i, 1] = ""; // convo dialogue
    }
    
    active = false;
    convoDialogueCount = 0; // number of lines in a specific conversation
    convoIndex       = 0; //current index towards our convoDialogueCount
    spriteToDisplay = -1; // avatar to display
    stringToDisplay = ""; // conversation line to display
    currCharIndex   = 1; //current character index of string to apply
    currChar = "";
    
    
    //dialogue display properties
    avatarScale = 1;
    avatar_xOrigin = view_xview[0] + 32;
    avatar_yOrigin = view_yview[0] + 32;
    
    text_xOrigin = view_xview[0] + 64;
    text_yOrigin = view_yview[0] + 14;
    
    
    scr_draw_dialogue:

    Code:
    //Padding for inside dialogue box
    var padding = 32;
    
    //Max width & height
    max_width = view_wview - (padding*2);
    max_height = (view_hview/4)-(.25*(view_hview/4));
    
    //draw dialogue boxes
    
    var bw = 4; // Border width
    if (active) {
    draw_set_font(fnt_dialogue);
    draw_set_color(c_black);
    draw_line_width(view_xview, view_yview + 5 , view_xview, view_yview + 60, bw*400);
    
    draw_set_color(c_white);
    draw_line_width(view_xview, view_yview + 5 , view_xview, view_yview+60, bw);
    draw_line_width(view_xview-(bw/2), view_yview + 5, view_xview+view_wview, view_yview + 5 , bw);
    draw_line_width(view_xview+view_wview-bw/2, view_yview + 5  , view_xview+view_wview-bw/2, view_yview + 60, bw);
    draw_line_width(view_xview - 2, view_yview + 60, view_xview+view_wview, view_yview + 60, bw);
    
    draw_set_color(c_white)
    draw_text(text_xOrigin, text_yOrigin, stringToDisplay);
    draw_sprite_ext(spriteToDisplay, -1, avatar_xOrigin, avatar_yOrigin, avatarScale, avatarScale, 0, c_white, 1);
    
    
    }
    

    And then I have my obj_dialogue.

    Create Event:
    Code:
    scr_initialize_dialogue();
    active = true;
    if (active)
    {
    convo_valentin1(); //conversation being shown
    }
    vocalized = false; //irrelevant
    
    count = 0;
    Step Event:
    Code:
    scr_DisplayConvoText();
    if (currCharIndex < string_length(dialogue[convoIndex, 1])) //for sound, irrelevant
    {
       spriteToDisplay = dialogue[convoIndex, 0];
       currChar = string_char_at(dialogue[convoIndex, 1], currCharIndex);
       stringToDisplay += currChar;
       currCharIndex += 1;
    
       if (currChar != " ") {
       audio_play_sound(snd_readables, 5, false);
    }
    }
    
    
    if keyboard_check_pressed(ord('Z')){
    count = count + 1;
    }
    
    if instance_exists(self) //irrelevant{
    room_speed = 15;
    }
    else{
    room_speed = 30;}
    
    if (count == 10) //if the last line is displayed{
    alarm_set(0,room_speed * 2.7);
    }
    if !(active){ //if text is skipped, jump straight to next scene
    room_goto(room_dark);
    instance_deactivate_object(obj_valentin_scary);
    instance_deactivate_object(obj_valentin2);
    instance_deactivate_object(obj_view);
    instance_destroy(obj_valentin);
    
    if (global.boy) {
    instance_destroy(obj_nonplayer1_s1);
    }
    if (global.girl) {
    instance_destroy(obj_nonplayer2_s1);
    }
    }
    
    
    Draw Event:
    Code:
    scr_draw_dialogue();
    Alarm 0:
    Code:
    //once final line of dialogue displays, alarm is set. When alarm goes off, this happens.
    
    room_goto(room_dark);
    instance_deactivate_object(obj_valentin_scary);
    instance_deactivate_object(obj_valentin2);
    instance_deactivate_object(obj_view);
    instance_destroy(obj_valentin);
    
    if (global.boy) {
    instance_destroy(obj_nonplayer1_s1);
    }
    if (global.girl) {
    instance_destroy(obj_nonplayer2_s1);
    }
    
    Going back to my scr_DisplayConvoText, I have it set so that the player can only press SPACE to continue the dialogue if the text has finished displaying. This works, so I decided to put count = count + 1 under this code, meaning that when the player presses space AND the next line of text is displayed, the count goes up by 1 (starting at 0). If the dialogue is no longer active, count = 0 (so it can restart each dialogue).

    Going to my step event, I set it so that when count == 10 (the last line of text), blahblahblah happens. But this isn't working, and I have no idea why. :\ Please help!
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    5,431
    Probably because you're constantly resetting the alarm every step. You set the alarm when count is 10 and count stays 10 for quite a while.
     
  3. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    139
    So what should I change to fix this?
     
  4. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    5,431
    The simplest method is just to make sure the alarm hasn't been set already.

    if !alarm[0]
     
  5. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    139
    Okay, so I changed it to
    Code:
    if (count == 10) && !(alarm[0]){
    alarm_set(0,room_speed * 2.7);
    }
    But that didn't fix the problem
     
  6. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    5,431
    Because you set count to 0 in scr_displayConvoText rather than when the convo is initialized.
     
  7. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    139
    Okay, so I should delete count = 0 from scr_DisplayConvoText and put it in the create event instead? Or in scr_initialize_dialogue?
     
  8. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    5,431
    Probably initialize_dialogue. That only gets called once per dialogue, doesn't it?
     
  9. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    139
    putting it in my create event actually fixed the problem. Thanks!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice