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

Sound effect exceptions? (SOLVED)

Fixer90

Member
So here's my wonderful textbox system:

CREATE EVENT:
Code:
///Initialize Textbox

if(global.invisible_box == true)
{
    textbox_alpha = 0;
}
else
{
    textbox_alpha = 1;
}
textbox_width = 504;
textbox_height = 380;
textbox_padding = 12;

textbox_start = ds_list_create();
ds_list_add(textbox_start, 0);

textbox_count = 0;
textbox_last_space = 0;
textbox_line = 0;

textbox_string = "";
STEP EVENT:
Code:
///Destroy Textbox

if(global.textbox_destroy == true)
{
    global.textbox_destroy = false;
    instance_destroy();
}
DRAW EVENT:

Code:
///Draw Textbox

if(global.orientation == "top")
{
    draw_sprite_ext(spr_textbox, 0, view_xview[0] + 6, view_yview[0] + 6, 1, 1, 0, c_white, textbox_alpha);
}
else
{
    draw_sprite_ext(spr_textbox, 0, view_xview[0] + 6, view_yview[0] + 282, 1, 1, 0, c_white, textbox_alpha);
}

draw_set_alpha(1);
draw_set_color(global.textbox_color);

draw_set_font(fnt_ar_julian);

if(global.centered == true)
{
    draw_set_halign(fa_center);
    draw_set_valign(fa_middle);
}
else
{
    draw_set_halign(fa_left);
    draw_set_valign(fa_top);
}

if(string_width(textbox_string) > textbox_width - textbox_padding - textbox_padding)
{
    global.textbox_message = string_delete(global.textbox_message, textbox_last_space, 1);
    global.textbox_message = string_insert("#", global.textbox_message, textbox_last_space);
    ds_list_add(textbox_start, textbox_last_space + 1);
}

if(textbox_count < string_length(global.textbox_message))
{
    if(!string_char_at(global.textbox_message, textbox_count) == " ")
    {
        audio_play_sound(snd_text, 10, false);
    }
    if(string_char_at(global.textbox_message, textbox_count) == " ")
    {
        textbox_last_space = textbox_count;
    }
    if(current_time mod 2 == 0)
    {
        textbox_count ++;
    }
}

if(string_height(textbox_string) > textbox_height - textbox_padding)
{
    textbox_line ++;
}

textbox_string = string_copy(global.textbox_message, ds_list_find_value(textbox_start, textbox_line), textbox_count - ds_list_find_value(textbox_start, textbox_line));

if(global.orientation == "top")
{
    if(global.centered == true)
    {
        draw_text(view_xview[0] + 256 + textbox_padding, view_yview[0] + 50 + textbox_padding, textbox_string);
    }
    else
    {
        draw_text(view_xview[0] + 4 + textbox_padding, view_yview[0] + 4 + textbox_padding, textbox_string);
    }
}
else
{
    if(global.centered == true)
    {
        draw_text(view_xview[0] + 256, view_yview[0] + 384 - 50, textbox_string);
    }
    else
    {
        draw_text(view_xview[0] + 4 + textbox_padding, view_yview[0] + 384 - 100 - 4 + textbox_padding, textbox_string);
    }
}
Now, as you can see in the Draw event, it plays a nice little text-blip sound effect called "snd_text". What I am seeking is a way to make it not play the sound when it gets to a " " (space). It acts like a typewriter text system, making blips at every character. So how do I make an exceptions for spaces?
 

obscene

Member
I think you have the right idea but have a small syntax issue...

if(!string_char_at(global.textbox_message, textbox_count) == " ")

I could be wrong, as this stuff gets tricky, but you are basically saying " if NOT the character at this position equals space" and I'd be curious as to the result that is returning. (What's the opposite of a character?) I'm wondering if this line would work correctly if you simply changed it to...

if(string_char_at(global.textbox_message, textbox_count) != " ")

I can confirm in my own project I have a line that removes spaces from a string and it works well with the simple " " as you tried.

while string_char_at(credits,pos+1) == " " pos+=1;
 

Fixer90

Member
I think you have the right idea but have a small syntax issue...

if(!string_char_at(global.textbox_message, textbox_count) == " ")

I could be wrong, as this stuff gets tricky, but you are basically saying " if NOT the character at this position equals space" and I'd be curious as to the result that is returning. (What's the opposite of a character?) I'm wondering if this line would work correctly if you simply changed it to...

if(string_char_at(global.textbox_message, textbox_count) != " ")
Putting it as != worked great! Thanks!
 
Top