Zahk
Member
I'll start by saying I'm a beginner - I'm only just starting to get the hang of GML, and I hesitate to even say that, especially given my current predicament.
I'm using a version of the dialog system created by Heartbeast in his RPG tutorial videos from a few years ago, which I've modified to suit my purposes. Almost everything is finally working as I intended - after days of agonizingly slow progress as I struggled to grasp and alter the code - but I just noticed that there seems to be a strange threshold of printed text that the draw_GUI event needs to reach before the player can continue to the next message/step of the array. That would be fine if that threshold were the end of the string, just like my code seems to say, but for some reason it's about halfway through a full dialog box. If the string is only a few words, the game doesn't recognize that the 'confirm_key' is pressed to continue to the next stage of the array for a couple of seconds after the string is finished printing. If the visible string passes this inexplicable threshold, the player can skip to the next step of the array before the current string has finished printing. Though I can explain that this is happening, I can't explain why, because the code seems like it should be working as intended to me. So, instead of throwing in the towel, I've come here for help.
The code is sprawled out over a few scripts and objects, so I'll just try to include the parts I believe are relevant:
This is in scr_talk_state, which is in the player's step event. "speaker" is the NPC instance:
And this is in the Draw GUI event for the dialog box (obj_dialog_box):
If you need to see more, please let me know. Any and all help is appreciated; I desperately want to be done with this so I can finally move on to the rest of the game, without worrying about the damn dialog system.
I'm using a version of the dialog system created by Heartbeast in his RPG tutorial videos from a few years ago, which I've modified to suit my purposes. Almost everything is finally working as I intended - after days of agonizingly slow progress as I struggled to grasp and alter the code - but I just noticed that there seems to be a strange threshold of printed text that the draw_GUI event needs to reach before the player can continue to the next message/step of the array. That would be fine if that threshold were the end of the string, just like my code seems to say, but for some reason it's about halfway through a full dialog box. If the string is only a few words, the game doesn't recognize that the 'confirm_key' is pressed to continue to the next stage of the array for a couple of seconds after the string is finished printing. If the visible string passes this inexplicable threshold, the player can skip to the next step of the array before the current string has finished printing. Though I can explain that this is happening, I can't explain why, because the code seems like it should be working as intended to me. So, instead of throwing in the towel, I've come here for help.
The code is sprawled out over a few scripts and objects, so I'll just try to include the parts I believe are relevant:
This is in scr_talk_state, which is in the player's step event. "speaker" is the NPC instance:
Code:
with (speaker) {
//Turn the sprite
if (x > obj_player.x) {
sprite_index = left_sprite;
} else if (x < obj_player.x) {
sprite_index = right_sprite;
}
if (y > obj_player.y) {
sprite_index = up_sprite;
} else if (y < obj_player.y) {
sprite_index = down_sprite;
}
if (!instance_exists(dialog)) {
dialog = instance_create_depth(camera_get_view_x(view_camera[0]), camera_get_view_y(view_camera[0]) + camera_get_view_height(view_camera[0]), 0, obj_dialog_box);
dialog.text = text;
} else {
if (obj_player.confirm_key and dialog.text_count >= string_length(dialog.text[text_page])) {
dialog.text_page++;
dialog.text_count = 0;
if (dialog.text_page > array_length_1d(dialog.text)-1) {
sprite_index = default_sprite;
with (obj_player) {
speaker = noone;
state = scr_move_state;
}
with (dialog) {
instance_destroy();
}
}
}
}
}
Code:
if (string_char_at(text[text_page], text_count) == " ") {
last_space = text_count;
} else {
last_space = noone;
}
if (last_space != noone) {
var text_words = scr_string_copy_words(text[text_page], 1, text_count);
if (string_width(text_words)*display_scale >= width-(xmargin)) {
//Remove the space
text[text_page] = string_delete(text[text_page], last_space, 1)
//Add a return. Using "\n" will enter a return (like pressing enter)
text[text_page] = string_insert("\n", text[text_page], last_space);
}
}
text_visible = string_copy(text[text_page], 0, text_count);
var xx = (x - camera_get_view_x(view_camera[0])) * display_scale;
var yy = ((y-48) - camera_get_view_y(view_camera[0])) * display_scale;
draw_text_ext_transformed(xx+xmargin, yy+ymargin, text_visible, 8, width, display_scale, display_scale, image_angle);
if (obj_player.confirm_key_held) {
spd = .99;
} else {
spd = .5;
}
text_count += spd;
Last edited: