• 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!

GML [SOLVED]Need portrait to change with text, but only when sentence has finished.

A

Agletsio

Guest
What I'm trying to do is simply: Let the portrait change whenever the sentence has reached its end and I press "Z".

Initially when I pressed Z, even before the sentence finished, the portraits would change before the sentence was finished.

if keyboard_check_pressed(ord("Z")) {
por_current += 1;
}

So I added the (characters = message_lengh) as extra argument but now the portrait doesn't change until the entire conversation is finished.

if keyboard_check_pressed(ord("Z")) && (characters = message_length) {
por_current += 1;
}

Tried a few different variations of this but can't figure out the problem. Any help or guidance would seriously be appreciated!

Create Event:
Code:
//Typewriter effect

anim_done = false;

iswriting = false;

message[0] = "Hello"
message[1] = "Hello?"
message[2] = "How are you?"
message[3] = "...who are you?"
message[4] = "If only you knew..."
message[5] = "Knew what?"
message[6] = ""

message_current = 0;
message_end = 6;
message_draw = "";
increase = 0.37;
characters = 0;
hold = 0;

message_length = string_length(message[message_current]);


//Portraits

por_current = 0;

por[0] = spr_por_1
por[1] = spr_por_2
por[2] = spr_por_2
por[3] = spr_por_1
por[4] = spr_por_2
por[5] = spr_por_1
por[6] = ""
Step Event

Code:
if (characters < message_length) { //if current character count is less than the amount in current message*
    hold = keyboard_check(ord("Z")); //hold is true or false if we hold 'Z' or not
    characters += increase * (1 + hold); //increase speed based on hold
    message_draw = string_copy(message[message_current], 0, characters); //copy string to current character
}

else

{ //if current character is more than the amount in the current message
    if (keyboard_check_pressed(ord("Z"))) { //if we press Z...
        if (message_current < message_end) { //if there are more messages left to show (0 -> 6, in our case)
            message_current += 1; //increase the message by 1
            message_length = string_length(message[message_current]);  //get the new character length for message
            characters = 0; //set the characters back to 0
            message_draw = ""; //clear the drawn text
        }
        else { //if our messages are done (we reach 6, in our case)...
            if message_current = 6 {iswriting = false;} //destroy the object
        }
    }
}

if keyboard_check_pressed(ord("Z")) && (characters >= message_length) /*(characters = message_length)*/ {
por_current += 1;
}

if por_current > 5 {
iswriting = false;
}
Draw Event

Code:
if iswriting = true {
draw_set_font(font0);
draw_set_halign(fa_left)
draw_text(320,835, message_draw); //draw the text at the coordinates
}
if iswriting = true {
draw_sprite(por[por_current],0,190,890)
}

if anim_done = true {
draw_sprite(sprite0,0,1398,667)
}
 
A

Agletsio

Guest
HI @TheouAegis,

Yes, that's exactly what I need to happen. Sorry for the misunderstanding, sometimes find it hard to word my problem when it comes to coding.

The problem is while the sentence (or message_current) is "typing", I can still press Z and the portrait will change. So character 1 will still be "talking" but you're able to change to character 2's portrait before the former is done.

Does that make sense?
 

TheouAegis

Member
What I'm saying is you have this:
Code:
if (characters < message_length) { //if current character count is less than the amount in current message*
   hold = keyboard_check(ord("Z")); //hold is true or false if we hold 'Z' or not
   characters += increase * (1 + hold); //increase speed based on hold
   message_draw = string_copy(message[message_current], 0, characters); //copy string to current character
}

else

{ //if current character is more than the amount in the current message
   if (keyboard_check_pressed(ord("Z"))) { //if we press Z...
       if (message_current < message_end) { //if there are more messages left to show (0 -> 6, in our case)
           message_current += 1; //increase the message by 1
           message_length = string_length(message[message_current]);  //get the new character length for message
           characters = 0; //set the characters back to 0
           message_draw = ""; //clear the drawn text
       }
       else { //if our messages are done (we reach 6, in our case)...
           if message_current = 6 {iswriting = false;} //destroy the object
       }
   }
}
Supposedly you can't skip to the next message in the dialogue until characters < message_length. Then the player has to let go of the Z key in order to get it to go to the next message in the dialogue. At that point, the portrait should be changed.

So in that same block where you set message_draw to "" and characters to 0, set the new portrait.
 
Top