OFFICIAL Coffee-break Tutorial: Easy Typewriter Dialogue

Cpaz

Member
God bless you Nocturne, I've been trying to find the best approach to this for a while now.
This is good stuff.
 

Evanski

Raccoon Lord
Forum Staff
Moderator
@Nocturne forgot his underscores in the most important line of his code

var len = string_length(text[text_current]); if (char_current < len) {char_current += char_speed;}

also he talkl to much

0.png

1.png
 
Howdy, I'm following the GML version of this tutorial and receiving some errors.

Within the string_wrap script:
function string_wrap(_text, _width)

Within the script it says: "unnecessary expression function used as a statement"

When compiling it says: "Script: string_wrap at line 6 : Assignment operated expected"
As well as: "Script: string_wrap at line 6 : malformed assignment statement"

Originally I typed the script's code as shown in the tutorial, so I thought I would copy/paste it in, just in case I typed something incorrectly, but it still comes up.

Code:
/// @function                   string_wrap(text, width);
/// @param  {string}    text    The text to wrap
/// @param  {real}      width   The maximum width of the text before a line break is inserted
/// @description        Take a string and add line breaks so that it doesn't overflow the maximum width

function string_wrap(_text, _width)
{
var _text_wrapped = "";
var _space = -1;
var _char_pos = 1;
while (string_length(_text) >= _char_pos)
    {
    if (string_width(string_copy(_text, 1, _char_pos)) > _width)
        {
        if (_space != -1)
            {
            _text_wrapped += string_copy(_text, 1, _space) + "\n";
            _text = string_copy(_text, _space + 1, string_length(_text) - (_space));
            _char_pos = 1;
            _space = -1;
            }
        }
    if (string_char_at(_text,_char_pos) == " ")
        {
        _space = _char_pos;
        }
    _char_pos += 1;
    }
if (string_length(_text) > 0)
    {
    _text_wrapped += _text;
    }
return _text_wrapped;
}
 
I'm also having some problems with the Key Press - Space event within the dialog object.

For line 17 it says: "number of arguments expected 0 got 2"
text[text_current] = string_wrap(text[text_current], text_width);

Line 19: "unexpected syntax error"
}

Code:
/// @description Insert description here
// You can write your code in this editor
var _len = string_length(text[text_current]);
if (char_current < _len)
    {
    char_current = _len;
    }
else
    {
    text_current += 1;
    if (text_current > text_last)
        {
        room_restart();
        }
    else
        {
        text[text_current] = string_wrap(text[text_current], text_width);
        char_current = 0;
        }
    }
 
Top