Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Technocrat on Wed 08/08/2012 21:06:55

Title: A "typing" effect of text in labels...
Post by: Technocrat on Wed 08/08/2012 21:06:55
I've been attempting to create a script that "types" text into a label, one letter at a time. It starts by the player entering the name of the label in the function (LabelName), and the text of the string to type (TypeText). It should then, running through the "while" cycle, add an extra letter on to the string "TextInProgress" from the "TypeText" string, and update the label, before returning to the beginning and moving on to the next letter.

This, unfortunately, is not the case. It seems instead to just make the label "LabelName" blank. I'd been putting in display functions to tell me what it had been doing, so I'm certain that it's moving up through the numbers, just not adding the letters on to the TextInProgress string.

Can anybody see what I'm missing here?

Code (AGS) Select

function TechnoTextType(Label *LabelName, String TypeText){
  int TotalLetters = TypeText.Length;
  int LetterOn = 0;
  String TextInProgress = "";
 
  while(LetterOn<TotalLetters){
    TextInProgress.AppendChar(TypeText.Chars[LetterOn]);
    LabelName.Text = TextInProgress;
    LetterOn++;
    Wait(1);
  }
}
 
Title: Re: A "typing" effect of text in labels...
Post by: Crimson Wizard on Wed 08/08/2012 21:19:39
Quote from manual:
Quote
IMPORTANT: The newly extended text is returned as a new string from this command. The original string will NOT be changed.

You should do:
Code (ags) Select

TextInProgress = TextInProgress.AppendChar(TypeText.Chars[LetterOn]);


AGS strings are fixed strings as far as I know, they cannot change, only be assigned a new value.
Title: Re: A "typing" effect of text in labels...
Post by: Technocrat on Wed 08/08/2012 21:25:34
Aahhh, many thanks! I'd read that bit in the manual, but it hadn't quite sunk in how it would apply to my current dilemma. Cheers!
Title: Re: A "typing" effect of text in labels...
Post by: Technocrat on Wed 08/08/2012 22:26:57
Okay, one more stupid question now that I've rejigged it. It runs through it with the typing effect, but for some reason it types, then deletes the first letter of the input string - in this case, it cuts the "h" from "hello world". Granted, the lazy answer is "put a space at the beginning of the string", but I want to understand what's wrong with it!

Code (AGS) Select

function TechnoTextType(Label *LabelName, String TypeText){
  int TotalLetters = TypeText.Length;
  int LetterOn = 0;
  String TextInProgress = " ";
 
 
  while(LetterOn<TotalLetters+1){
    if(LetterOn>0)TextInProgress = TextInProgress.Truncate(LetterOn-1);
    TextInProgress = TextInProgress.AppendChar(TypeText.Chars[LetterOn]);
    TextInProgress = TextInProgress.AppendChar('|');
    LabelName.Text = TextInProgress;
    LetterOn++;
    Wait(2);
  }
  TextInProgress = TextInProgress.Truncate(TotalLetters-1);
  LabelName.Text = TextInProgress;

}
Title: Re: A "typing" effect of text in labels...
Post by: Crimson Wizard on Wed 08/08/2012 22:44:52
I am afraid I don't fully comprehend the logic beyond truncation right away.
I can state the simple fact that on second iteration of while loop the string is being truncated to zero length.

- LetterOn = 0;
=== first iteration ===
- TextInProgress = Chars[LetterOn (that is 0)] + '|', that gives "h|"?
- LetterOn++, that gives LetterOn = 1
=== second iteration ===
- LetterOn = 1, > 0; TextInProgress = TextInProgress.Truncate(1 - 1 = 0); truncates TextInProgress to zero characters, deleting "h|"