Author Topic: MODULE: Typewriter Text v1.2 - Customizable Typewriter style text.  (Read 5189 times)

See a few posts down for the code.

Code: Adventure Game Studio
  1. Typewriter.Type (int x, int y, int delay, int color, int font,
  2.                  String text, style, display, optional AudioClip sound,
  3.                  optional TypewriterFlash flash);
           
Displays 'text' as typwriter text at 'x' and 'y', in color 'color',
with a delay of 'delay' (in game loops) between characters, using
font 'font'

Style specifies which style you want to use.

Code: Adventure Game Studio
  1. eTypewriter_LongSpace
 
Spaces are delayed twice as long as other characters.
 
Code: Adventure Game Studio
  1. eTypewriter_Constant
 
All increments are delayed equally.

Code: Adventure Game Studio
  1. eTypewriter_ShortSpace
 
Spaces are delayed half the length of other characters.

Code: Adventure Game Studio
  1. eTypeWriter_Mixed
 
Spaces are randomized to be either half, double or the same as other
characters.

Pass an audio clip name as sound to play a sound with each letter.
Leave it out (or pass as '0') for no sound.

Set TypewriterFlash to eTypewriter_Flash to have the last character flash
in and out, and to eTypewriter_DontFlash to keep the last character
steady.

Display can either be displaying the effect on an Overlay or on a GUI element (either a button or a label)

eg.

Code: Adventure Game Studio
  1. Typewriter.Type (5, 185, 3, 65535, eFontNormal, "Write your text here[[AND WATCH IT TYPE ITSELF", eTypewriter_ShortSpace, eTypewriterDisplay_Overlay, aPop);

EDIT BY DUALNAMES: You simply import the module after downloading it from here.

http://duals.agser.me/Modules/Typewriter.zip

I've added some extra functionality. Check the header of the module for information and examples.

EDIT BY PHEMAR:

Dualnames' link seems to be broken. Original can be found here:

https://www.dropbox.com/s/vyeujxo7gbr06hk/Typewriter.zip?dl=0
« Last Edit: 07 Apr 2018, 15:16 by Phemar »

Slasher

  • slasher
    • I can help with AGS tutoring
    • Lifetime Achievement Award Winner
    • I can help with scripting
    • I can help with story design
    • Slasher worked on one or more games that won an AGS Award!
    •  
    • Slasher worked on one or more games that was nominated for an AGS Award!
Great stuff Phemar

Lots of people are looking for this type of display ;)

cheers

Thanks! The code works perfectly so far, I haven't found any bugs. The only annoyance I've found is that I can't create a pointer to a font in the function's arguments.
So if you need to use different fonts throughout your usage of Typewriter, you're either gonna have to copy paste the code for each font or just not use it :/

Does anyone know if there's a way to do this?
« Last Edit: 24 Apr 2013, 09:50 by Phemar »

geork

  • measure once, cut twice, say it was already broken
    • I can help with scripting
    • I can help with voice acting
You can reference a font through it's enumerated index. Something like:
Code: Adventure Game Studio
  1. int f = eFontFont0;
  2. Overlay *v = Overlay.CreateTextual(40, 40, 40, f, 6, "hi!");//where f stands in for the FontType parameter

I don't know if the wording I've used is correct, but the code works :-D

You can reference a font through it's enumerated index. Something like:
Code: Adventure Game Studio
  1. int f = eFontFont0;
  2. Overlay *v = Overlay.CreateTextual(40, 40, 40, f, 6, "hi!");//where f stands in for the FontType parameter

I don't know if the wording I've used is correct, but the code works :-D

Thanks, that seems to work perfectly.

Anyway, I'm just going to post the code here, as it's easier for me to keep it updated.

V1.2

Script Header:
Code: Adventure Game Studio
  1. //Expressed as MAXIMUM_DISPLAY_TIME * (delay * 4)
  2. //Therefore, a delay setting of 3 and a maximum time of 5
  3. //will wait 60 game loops before removing the text
  4. #define TYPEWRITER_MAXIMUM_DISPLAY_TIME 5
  5.  
  6. enum TypewriterStyle {
  7.   eTypewriter_LongSpace,
  8.   eTypewriter_Constant,
  9.   eTypewriter_ShortSpace,
  10.   eTypeWriter_Mixed,
  11. };
  12.  
  13. enum TypewriterFlash {
  14.   eTypewriter_Flash = true,
  15.   eTypewriter_DontFlash = false,
  16. };
  17.  
  18. struct Typewriter {
  19.   import static void Type (int x, int y, int delay, int color, int font,
  20.                            String text, TypewriterStyle style,
  21.                            AudioClip *sound = 0, TypewriterFlash flash = true);
  22. };

Main Script:
Code: Adventure Game Studio
  1. Overlay *olTypedText;
  2.  
  3. static void Typewriter::Type (int x, int y, int delay, int color, int font,
  4.                               String text, TypewriterStyle style,
  5.                               AudioClip *sound, TypewriterFlash flash) {
  6.  
  7.   String displayedLine = "";
  8.  
  9.   olTypedText = Overlay.CreateTextual (x, y, System.ViewportWidth - x,
  10.                                        font, color, displayedLine);
  11.  
  12.   Wait (delay);
  13.  
  14.   int i = 0;
  15.   while (i < text.Length) {
  16.    
  17.     displayedLine = String.Format ("%s%c", displayedLine, text.Chars[i]);
  18.     olTypedText.SetText (System.ViewportWidth - x, font, color, displayedLine);
  19.    
  20.     if (style == eTypewriter_LongSpace) {
  21.       if (text.Chars[i] == ' ')
  22.        Wait(delay*2);
  23.       else if (text.Chars[i] == '[')
  24.        Wait(delay*4);
  25.       else {
  26.         if (sound)
  27.           sound.Play ();
  28.         Wait(delay);
  29.       }
  30.     }
  31.    
  32.     else if (style == eTypewriter_Constant) {
  33.       if (text.Chars[i] == ' ')
  34.        Wait(delay);
  35.       else if (text.Chars[i] == '[')
  36.        Wait(delay*2);
  37.       else {
  38.         if (sound)
  39.           sound.Play ();
  40.         Wait(delay);
  41.       }
  42.     }
  43.    
  44.     else if (style == eTypewriter_ShortSpace) {
  45.       if (text.Chars[i] == ' ')
  46.        Wait(delay/2);
  47.       else if (text.Chars[i] == '[')
  48.        Wait(delay*2);
  49.       else {
  50.         if (sound)
  51.           sound.Play ();
  52.         Wait(delay);
  53.       }
  54.     }
  55.    
  56.     else if (style == eTypeWriter_Mixed) {
  57.       int r = Random(2);
  58.       if (text.Chars[i] == ' ') {
  59.        if (r == 0)
  60.           Wait (delay*2);
  61.         else if (r == 1)
  62.           Wait (delay/2);
  63.         else
  64.           Wait (delay);
  65.       }
  66.       else if (text.Chars[i] == '[') {
  67.        if (r == 0)
  68.           Wait (delay*2);
  69.         else
  70.           Wait (delay*4);
  71.       }
  72.       else {
  73.         if (sound)
  74.           sound.Play ();
  75.         Wait (delay);
  76.       }
  77.     }
  78.    
  79.     i++;
  80.  
  81.   }
  82.  
  83.   if (flash == eTypewriter_Flash) {
  84.      i = 0;
  85.     while (i < TYPEWRITER_MAXIMUM_DISPLAY_TIME) {
  86.       olTypedText.SetText (System.ViewportWidth - x, font, color,
  87.                            displayedLine.Truncate (displayedLine.Length - 1));
  88.       Wait (delay*2);
  89.       displayedLine = String.Format ("%s%c", displayedLine, text.Chars[displayedLine.Length]);
  90.       olTypedText.SetText (System.ViewportWidth - x, font, color, displayedLine);
  91.       Wait (delay*2);
  92.       i++;
  93.     }
  94.   }
  95.  
  96.   else if (flash == eTypewriter_DontFlash) {
  97.     Wait (TYPEWRITER_MAXIMUM_DISPLAY_TIME * (delay * 4));
  98.   }
  99.  
  100.   if (olTypedText.Valid)
  101.     olTypedText.Remove ();
  102.  
  103. }
« Last Edit: 24 Apr 2013, 12:19 by Phemar »

Hi,

I really have a need for this script to work for me in a game I am working on.
The easiest way to explain how I will use it is that it will be a game simular in style to how shadowgate
displays text down in a text box as you enter into rooms or look at things that style of typing on screen.

This code looks like it will work for that but I am unsure as exactly what script files or locations to put the script.

is the header section suppossed to go in globalscript.ash
and the part that says goes in the main go in globalscript.acs just somewhere?
not sure exactly where I put this
« Last Edit: 06 Jan 2014, 14:11 by jamesreg »

Dualnames

  • Local Moderator
  • Rottwheelers
  • Pretty Badass
    • Dualnames worked on one or more games that won an AGS Award!
    •  
    • Dualnames worked on one or more games that was nominated for an AGS Award!
You simply import the module after downloading it from here.

http://duals.agser.me/Modules/Typewriter.zip

I've added some extra functionality. Check the header of the module for information and examples.
No more military army stuff. I'm alive and back.

Is there a way to get this script to pause the text will mouse or keyboard press before moving onto other scripts?
« Last Edit: 07 Jan 2014, 20:55 by jamesreg »

Similar request:
I'm trying use the module for displaying speech but fail to implement any kind of skip-speech.
Is there any way of manipulating "TYPEWRITER_MAXIMUM_DISPLAY_TIME" or "delay" or something?

Also:
Code: Adventure Game Studio
  1. Typewriter.Type (5, 185, 3, 65535, eFontNormal, "Write your text here[[AND WATCH IT TYPE ITSELF", eTypewriter_ShortSpace, aPop);
..seems obsolete after Dualnames new functions. Right?

Edit: Forgot how to post code properly. Sorry.
« Last Edit: 12 Jan 2014, 01:05 by Dualnames »

Dualnames

  • Local Moderator
  • Rottwheelers
  • Pretty Badass
    • Dualnames worked on one or more games that won an AGS Award!
    •  
    • Dualnames worked on one or more games that was nominated for an AGS Award!
You have done a small mistake. Here's the correct line. You missed the eTypewriterDisplay parameter.
Code: Adventure Game Studio
  1. Typewriter.Type (5, 185, 3, 65535, eFontNormal, "Write your text here[[AND WATCH IT TYPE ITSELF", eTypewriter_ShortSpace, eTypewriterDisplay_Overlay, aPop);
  2.  
No more military army stuff. I'm alive and back.

I'm pretty sure that I copy pasted that line from the example in the first post. The missing eTypewriterDisplay parameter was kind of my point.  :-D
Oh well. Never mind. It works now anyway. Any ideas about my question btw?

Hi AGS, hope it's alright to reply to an older thread! I've been following all the instructions listed in this thread yet I still can't seem to fix this problem. I'm currently very new to visual programming, so more likely than not it's probably a beginner installation error on my part.

I've installed and tried Phemar's v1.2 update and Dualnames' version on separate trials, however I've encountered the same problem with both versions of the code:
The text box first appears about ~300 px below what I set int y, then quickly pans to the actual coordinate of int y. Additionally, I cannot set int x as any value other than "0" because the text box bumps along the screen - I suspect this is because it is automatically set to the same width as the game window (1024 px)? The actual typewriter effect itself works like a charm.

I'm currently testing this out as a "function cEgo_Interact()/Talk()/Look()" command with a simple black-box custom text GUI window.

The line of text I am specifically using is:
Code: Adventure Game Studio
  1. Typewriter.Type (0, 525, 3, 65535, eFontNormal, "Write your text here[[AND WATCH IT TYPE ITSELF", eTypewriter_Constant, eTypewriterDisplay_Overlay, null, eTypewriter_DontFlash);

I plan on using this effect for Display and Speech functions - for both I'd like to be able to set specific coordinates for where the Overlay box appears, though I am making custom GUIs for both these functions - which I suspect will use the "Typerwriter.Type" command instead. I'd appreciate any kind of feedback or explanation for what I'm doing wrong. Thanks for your time!
« Last Edit: 01 Sep 2015, 15:40 by TY »

Noto

  • tits out and touch faith
    • I can help with characters
    • I can help with proof reading
    • I can help with story design
    • I can help with translating
HATE to necro this old thread but I'm sort of out of options. I've searched everywhere and nothing else I've found can suit my needs like this module can (the sound effect feature in particular is something I find incredibly useful) and I'm essentially having the same issue as the poster above. Here is a visual demonstration:

https://gyazo.com/c2b0b4b381e58d1803e33d69e893d073

The typewriter effect works perfectly, but its coordinates are totally messed up. I'm not really a programmer and I've searched high and low for an alternative but have come up short. I'd really like to be able to use this module, as it's incredibly convenient. I'm fairly certain it's an issue with resolution, as all my lower-res games handle the module just fine. My game is 1920x1080, for reference. Thanks in advance for any help.

I am aware of Crimson Wizard's module here (https://www.adventuregamestudio.co.uk/forums/index.php?topic=54450.0) but using it gives me the exact same issue. What exactly is going on.

edit: thanks to the help of Crimson Wizard (seriously, I would have had no idea what this was otherwise) this was resolved! Having a custom GUI and the game being set to sierra-style speech screws with these two typewriter modules. I switched back to lucasarts speech afterward and it totally got rid of this problem. How odd.
« Last Edit: 24 Jun 2020, 08:40 by Noto »

There seem to be a curious bug either in AGS or somehow both typewriter modules has same error in them:

1) Set Sierra-style speech
2) Create a text window GUI and assign it default text-window
3) Call typewriter on overlay.

Text window GUI will be displayed as a text overlay background (not sure if it's a error on its own, could be original behavior), and that GUI randomly jumps around the screen.

UPDATE: This seem to be a pretty old bug, even AGS 3.2.1 has this.
« Last Edit: 24 Jun 2020, 23:44 by Crimson Wizard »

edit: thanks to the help of Crimson Wizard (seriously, I would have had no idea what this was otherwise) this was resolved! Having a custom GUI and the game being set to sierra-style speech screws with these two typewriter modules. I switched back to lucasarts speech afterward and it totally got rid of this problem. How odd.

Hey, this is only happening with overlays, so you could keep Sierra speech but use typewriter Label on GUI instead of Overlay.

But yea, this is an obscure ancient bug at least as old as AGS 3.2.1. Still not sure what is happening there, but looks like coordinates got broken at some point.

Noto

  • tits out and touch faith
    • I can help with characters
    • I can help with proof reading
    • I can help with story design
    • I can help with translating
Completely separate issue now. I'm trying to set up both of these modules in my game because I'm a crazy woman (I'm trying to use them for different purposes...) and Crimson's module is working perfectly while I'm still running into a snag with Phemar's. I'm using the 1.2 version by Dualnames (which I still have saved from a few years ago, actually! I can reupload that here if anyone is interested in having it) and butting up against a wall trying to get it to display on a GUI label. It will bring the GUI up and no text will print at all, but there's a delay as though it is doing it, just not visibly. Afterward, it gives me this error:

https://i.gyazo.com/88640c42d2160ac9f13c13c2c486b730.png

The exact line I'm using is:
Code: Adventure Game Studio
  1. Typewriter.Type (600, 600, 3, 6555, eFontDroidSans, "Everybody get up it's time to slam now, we got a real jam going on...", eTypewriter_Constant, eTypewriterDisplay_UIElement, null, eTypewriter_DontFlash, PlayerSpeech);
  2.  

If I comment out the error line the game doesn't crash, but it still doesn't print any text. Highly appreciate any help!
(And here's the Typewriter version I have: https://www.dropbox.com/s/qzx3zntl20j1lpy/Typewriter%201.2.rar?dl=0)