Author Topic: A "typing" effect of text in labels...  (Read 225 times)  Share 

Technocrat

  • AGS Baker
  • Always finishes what he sta
  • Technocrat worked on a game that was nominated for an AGS Award!Technocrat worked on a game that won an AGS Award!
A "typing" effect of text in labels...
« on: 08 Aug 2012, 21:06 »
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: Adventure Game Studio
  1. function TechnoTextType(Label *LabelName, String TypeText){
  2.   int TotalLetters = TypeText.Length;
  3.   int LetterOn = 0;
  4.   String TextInProgress = "";
  5.  
  6.   while(LetterOn<TotalLetters){
  7.     TextInProgress.AppendChar(TypeText.Chars[LetterOn]);
  8.     LabelName.Text = TextInProgress;
  9.     LetterOn++;
  10.     Wait(1);
  11.   }
  12. }
  13.  

Crimson Wizard

  • AGS Project Admins
  • not et suppotreD
    • I can help with translating
    •  
Re: A "typing" effect of text in labels...
« Reply #1 on: 08 Aug 2012, 21:19 »
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: Adventure Game Studio
  1. TextInProgress = TextInProgress.AppendChar(TypeText.Chars[LetterOn]);
  2.  

AGS strings are fixed strings as far as I know, they cannot change, only be assigned a new value.

Technocrat

  • AGS Baker
  • Always finishes what he sta
  • Technocrat worked on a game that was nominated for an AGS Award!Technocrat worked on a game that won an AGS Award!
Re: A "typing" effect of text in labels...
« Reply #2 on: 08 Aug 2012, 21:25 »
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!

Technocrat

  • AGS Baker
  • Always finishes what he sta
  • Technocrat worked on a game that was nominated for an AGS Award!Technocrat worked on a game that won an AGS Award!
Re: A "typing" effect of text in labels...
« Reply #3 on: 08 Aug 2012, 22:26 »
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: Adventure Game Studio
  1. function TechnoTextType(Label *LabelName, String TypeText){
  2.   int TotalLetters = TypeText.Length;
  3.   int LetterOn = 0;
  4.   String TextInProgress = " ";
  5.  
  6.  
  7.   while(LetterOn<TotalLetters+1){
  8.     if(LetterOn>0)TextInProgress = TextInProgress.Truncate(LetterOn-1);
  9.     TextInProgress = TextInProgress.AppendChar(TypeText.Chars[LetterOn]);
  10.     TextInProgress = TextInProgress.AppendChar('|');
  11.    LabelName.Text = TextInProgress;
  12.     LetterOn++;
  13.     Wait(2);
  14.   }
  15.   TextInProgress = TextInProgress.Truncate(TotalLetters-1);
  16.   LabelName.Text = TextInProgress;
  17.  
  18. }
  19.  

Crimson Wizard

  • AGS Project Admins
  • not et suppotreD
    • I can help with translating
    •  
Re: A "typing" effect of text in labels...
« Reply #4 on: 08 Aug 2012, 22:44 »
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|"
« Last Edit: 08 Aug 2012, 22:53 by Crimson Wizard »