Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Mugs on Fri 17/03/2006 03:58:55

Title: Understanding the TypeLine function. (SOLVED)
Post by: Mugs on Fri 17/03/2006 03:58:55
Alright,

I do not know how to use the typeline function, at all.Ã,  I am displaying text using a label inside of a GUI, like so:


textlabel.SetText("This is called text!");


Can anyone tell me what to do in order make a simple typewriting effect.

P.S. I've seen the original Typeline function before.


Title: Re: Understanding the TypeLine function.
Post by: Khris on Fri 17/03/2006 05:01:11
You mean this function (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=14437.0)?

Removetextid = CreateTextOverlay(xpos,50,400,font,colour,displayedline);

ReplaceSetTextOverlay(textid, 10,vspacing,400, font, colour, displayedline);withtextlabel.SetText(displayedline);

Then, instead of callingtextlabel.SetText("This is called text!");callTypeLine("This is called text!", 0);
Title: Re: Understanding the TypeLine function.
Post by: Mugs on Fri 17/03/2006 05:53:14
Thanks again, KhrisMUC

:-X Now let's test it...

??? Damn...

:( Error (line 10): Type mismatch: cannot convert 'const string' to 'string'

Any solutions?
Title: Re: Understanding the TypeLine function.
Post by: Khris on Fri 17/03/2006 06:32:57
Try

function TypeLine(const string line) {
...
}

(vspacing isn't needed anymore)
Title: Re: Understanding the TypeLine function.
Post by: Mugs on Fri 17/03/2006 06:49:18
Alright, I got rid of that problem.

But now I get this:

in Global Script
Error (line 13) type 'string' is no longer supported; use 'String' instead.

I know I can't just replace the letter 's' for an 'S'. That would give me:

Type mismatch: cannot convert 'String' to 'string'
Title: Re: Understanding the TypeLine function.
Post by: Gilbert on Fri 17/03/2006 07:01:50
Uncheck 'enforce new string' or something in the editor.

Though the best solution is to rewrite the functions...
Title: Re: Understanding the TypeLine function.
Post by: Mugs on Fri 17/03/2006 07:29:40
This is what I have:


function TypeLine(const string line) {

Ã, 
Ã,  int length=0;
Ã,  int i = 0;
Ã,  string displayedline_new;
Ã,  string displayedline_old;

Ã,  int textid = 0;

Ã,  length = 0;Ã, 
Ã,  i=0;
Ã,  StrCopy(displayedline_old," ");
Ã,  length=StrLen(line); //set string length
Ã,  while(i<length){
Ã,  Ã,  StrCopy(displayedline_new, displayedline_old);
Ã,  Ã,  StrFormat(displayedline_new, "%s%c", displayedline_old, StrGetCharAt(line,i));
Ã,  Ã,  i++;
Ã,  Ã,  text.SetText(displayedline_new);
Ã,  Ã,  PlaySound(1);
Ã,  Ã,  Wait(5);
Ã,  }
Ã,  return textid;
}


The game types each letter one by one,Ã,  but they type on top of eachother, which means, only one letter appears at a time.

What did I do wrong?
Title: Re: Understanding the TypeLine function.
Post by: Khris on Fri 17/03/2006 09:05:39
Try this:

function TypeLine(String line) {

Ã,  int length=line.Length;
Ã,  int i = 0;
Ã,  String displayedline="";

Ã,  while(i<length){
Ã,  Ã,  displayedline.AppendChar(line.Chars[i]);
Ã,  Ã,  text.SetText(displayedline);
Ã,  Ã,  PlaySound(1);
Ã,  Ã,  Wait(5);
Ã,  Ã,  i++;
Ã,  }
}
Title: Re: Understanding the TypeLine function.
Post by: Mugs on Fri 17/03/2006 16:54:32
I can hear sound, but I can't see the text.
Title: Re: Understanding the TypeLine function.
Post by: Mugs on Sat 18/03/2006 04:15:10
I've been looking at the script for a while.Ã,  I tried adding and modifing things,Ã,  and nothing works.Ã,  Ã,  What's wrong with the script?

EDIT: I double posted by accident, sorry.
Title: Re: Understanding the TypeLine function.
Post by: Khris on Sat 18/03/2006 16:16:06
After wondering what's wrong with it for hours, it suddenly came to me:
displayedline=displayedline.AppendChar(line.Chars[i]);

QuoteNOTE: The new concatenated string is returned as a new string from this function; it does NOT modify the original string.
Title: Re: Understanding the TypeLine function. (SOLVED)
Post by: Mugs on Sat 18/03/2006 19:20:36
 :D It works!!!Ã,  I can finally relax!Ã,  Ã, 


Thank you for helping me with this problem (and other problems in other threads :P)