EASY TYPEWRITER DIALOG TUTORIAL (i need help with error message) *FIXED*

H

HagRaven56

Guest
I completed the easy typewriter dialog tutorial, but when I run code, it gives me an error message for the string_wrap script.
says:
"unnecessary expression function used as a statement"

and this is the code line the tutorial has you place:
function string_wrap(_text, _width)

as well as this in the create event for the object:
"number of arguments expected 0 got 2

and this is the line of code:
text[text_current] = string_wrap(text_current, text_width);

I followed the tutorial but cannot seem to fix it
 
H

HagRaven56

Guest
Where's the rest of the function?
///this is the script asset, as the tutorial has it

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_wrap += _text;
}

return _text_wrapped;
}
 

Nidoking

Member
Then you can't define functions using that syntax. You'll need to make sure the tutorial you're using matches the version.
 
H

HagRaven56

Guest
hello Nidoking my apologies this took a while, I was trying to find out how to create functions in the current version I mentioned in the thread so that I could at least know how to do it but could not find it. In the end I did the update to 2.3 and sure enough it worked, I appreciate the help.
 

Nidoking

Member
Your old version didn't have functions. You would have needed to use a script resource, which is pretty much just the body of the function and using argument variables instead of defining arguments. But having upgraded to 2.3, you can now follow the tutorial you have.
 
Top