1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Dialogue sound

Discussion in 'Programming' started by samyak, Dec 24, 2017.

  1. samyak

    samyak Member

    Joined:
    Jul 19, 2016
    Posts:
    93
    How to attach sound with text like in 0:10 in this video?


    I'm using string_copy(string_xyz, 1, i ) and incrementing i+=0.4;
     
  2. CedSharp

    CedSharp Member

    Joined:
    Sep 5, 2016
    Posts:
    665
    The moment you increment "i", just play a sound?

    Code:
    if( text_is_not_done ) {
        i += 4;
        audio_play_sound( snd_textbox_male );
    }
    
     
  3. samyak

    samyak Member

    Joined:
    Jul 19, 2016
    Posts:
    93
    What is "text_is_not_done"? How do I know that?
    I had put this in the step event of the dialogue object-->

    print=string_copy(str[next],1,i);
    if i<=string_length(str[next]){ if i mod 1=0 and i mod 1<0.2 and string_char_at(str[next],i)!=" " {audio_play_sound(sound,1,false);} i+=0.2;}

    next=clamp(next,0,3);


    if next=0 and o_player.flip { instance_create_layer(x,y,1,o_another_object);i=0;}

    if distance_to_object(o_player)<65 and o_player.flip and next>0 and next< 3
    {

    next++; i=0;

    }

    ////////////////////////////////

    But this does not work properly.
     
  4. CedSharp

    CedSharp Member

    Joined:
    Sep 5, 2016
    Posts:
    665
    -

    First of all, you are dealing with CHARACTERS, why use a FLOAT value ?
    It doesn`t make sense.

    I usually use my own timing system for situations like this:
    Code:
    // Create Event
    text = "this is what I want to say";
    print = "";
    text_delay = 30; // Bigger value = slower text
    text_timer = current_time+text_delay;
    text_sound = snd_text_male;
    
    // Step Event
    if( current_time >= text_timer ) {
        if( string_length( print ) < string_length( text ) ) {
            print = string_copy( text, 1, string_length( print )+1 );
            audio_play_sound( text_sound, 1, false );
            text_timer += text_delay;
        }
    } 
    
    // Draw Event
    draw_text( x, y, print );
    
    The above uses a millisecond-based value ( internal variable current_time ).
    There is about 33 milliseconds per step in gamemaker, so you can be 30 time more precise using those :D
    The "text_is_not_done" was just an indicator to show you that you need a condition to check before playing the sound otherwise the sound will play even if the text is done being shown.
     
  5. samyak

    samyak Member

    Joined:
    Jul 19, 2016
    Posts:
    93
    I
    I will try your method soon. Thanks
     
    Last edited: Dec 24, 2017
  6. Cloaked Games

    Cloaked Games Member

    Joined:
    Jul 4, 2016
    Posts:
    821
    I want to add one thing to that, which is you should add a check for the character, and only play the sound if it is not a space. Then the sound will reflect the length of the words/pace of the text. I think that usually sounds better, as apposed to playing it every time.

    Otherwise, that's pretty much what I do. Good luck.
     
  7. samyak

    samyak Member

    Joined:
    Jul 19, 2016
    Posts:
    93
    That thing I've already achieved partially. I mean it worked sometime and did not work some other time, hence the problem.
     
  8. Cloaked Games

    Cloaked Games Member

    Joined:
    Jul 4, 2016
    Posts:
    821
    Use the check string_char_at.

    You can compare the final character to check if != " "
     
  9. samyak

    samyak Member

    Joined:
    Jul 19, 2016
    Posts:
    93
    I
    wrote ->
    if print!=" " { audio_play_sound( text_sound, 1, false );

    but it did not work....
     
  10. samyak

    samyak Member

    Joined:
    Jul 19, 2016
    Posts:
    93
    I tried your method. But there was sound even if there was Space.
     
  11. samyak

    samyak Member

    Joined:
    Jul 19, 2016
    Posts:
    93
    At first it worked, then after sometime somehow it did not work.
     
    Last edited: Dec 24, 2017
  12. Cloaked Games

    Cloaked Games Member

    Joined:
    Jul 4, 2016
    Posts:
    821
    print, based on your code, is the entire string, not just the last character. You have to put print into string_char_at to find the last character (the most recent one that was added to the string) to see if that one is a space. As it is it is basically never going to be equal to space.
     
    samyak likes this.
  13. samyak

    samyak Member

    Joined:
    Jul 19, 2016
    Posts:
    93
    I had wriiten
    if (string_char_at(str[next],string_length( print ))!=" " or string_char_at(str[next],string_length( print ))!=",") {}
    instead of
    if (string_char_at(str[next],string_length( print ))!=" " and string_char_at(str[next],string_length( print ))!=",") {

    That was the problem.

    But I have a new problem. New str[next] is not draw when next changes from 0 to 1 (for new sentence). I have to figure it out.
     

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