See a few posts down for the code.
Typewriter.Type (int x, int y, int delay, int color, int font,
String text, style, display, optional AudioClip sound,
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.
eTypewriter_LongSpace
Spaces are delayed twice as long as other characters.
eTypewriter_Constant
All increments are delayed equally.
eTypewriter_ShortSpace
Spaces are delayed half the length of other characters.
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.
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
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?
You can reference a font through it's enumerated index. Something like:
int f = eFontFont0;
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
Quote from: geork on Wed 24/04/2013 11:41:23
You can reference a font through it's enumerated index. Something like:
int f = eFontFont0;
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:
//Expressed as MAXIMUM_DISPLAY_TIME * (delay * 4)
//Therefore, a delay setting of 3 and a maximum time of 5
//will wait 60 game loops before removing the text
#define TYPEWRITER_MAXIMUM_DISPLAY_TIME 5
enum TypewriterStyle {
eTypewriter_LongSpace,
eTypewriter_Constant,
eTypewriter_ShortSpace,
eTypeWriter_Mixed,
};
enum TypewriterFlash {
eTypewriter_Flash = true,
eTypewriter_DontFlash = false,
};
struct Typewriter {
import static void Type (int x, int y, int delay, int color, int font,
String text, TypewriterStyle style,
AudioClip *sound = 0, TypewriterFlash flash = true);
};
Main Script:
Overlay *olTypedText;
static void Typewriter::Type (int x, int y, int delay, int color, int font,
String text, TypewriterStyle style,
AudioClip *sound, TypewriterFlash flash) {
String displayedLine = "";
olTypedText = Overlay.CreateTextual (x, y, System.ViewportWidth - x,
font, color, displayedLine);
Wait (delay);
int i = 0;
while (i < text.Length) {
displayedLine = String.Format ("%s%c", displayedLine, text.Chars[i]);
olTypedText.SetText (System.ViewportWidth - x, font, color, displayedLine);
if (style == eTypewriter_LongSpace) {
if (text.Chars[i] == ' ')
Wait(delay*2);
else if (text.Chars[i] == '[')
Wait(delay*4);
else {
if (sound)
sound.Play ();
Wait(delay);
}
}
else if (style == eTypewriter_Constant) {
if (text.Chars[i] == ' ')
Wait(delay);
else if (text.Chars[i] == '[')
Wait(delay*2);
else {
if (sound)
sound.Play ();
Wait(delay);
}
}
else if (style == eTypewriter_ShortSpace) {
if (text.Chars[i] == ' ')
Wait(delay/2);
else if (text.Chars[i] == '[')
Wait(delay*2);
else {
if (sound)
sound.Play ();
Wait(delay);
}
}
else if (style == eTypeWriter_Mixed) {
int r = Random(2);
if (text.Chars[i] == ' ') {
if (r == 0)
Wait (delay*2);
else if (r == 1)
Wait (delay/2);
else
Wait (delay);
}
else if (text.Chars[i] == '[') {
if (r == 0)
Wait (delay*2);
else
Wait (delay*4);
}
else {
if (sound)
sound.Play ();
Wait (delay);
}
}
i++;
}
if (flash == eTypewriter_Flash) {
i = 0;
while (i < TYPEWRITER_MAXIMUM_DISPLAY_TIME) {
olTypedText.SetText (System.ViewportWidth - x, font, color,
displayedLine.Truncate (displayedLine.Length - 1));
Wait (delay*2);
displayedLine = String.Format ("%s%c", displayedLine, text.Chars[displayedLine.Length]);
olTypedText.SetText (System.ViewportWidth - x, font, color, displayedLine);
Wait (delay*2);
i++;
}
}
else if (flash == eTypewriter_DontFlash) {
Wait (TYPEWRITER_MAXIMUM_DISPLAY_TIME * (delay * 4));
}
if (olTypedText.Valid)
olTypedText.Remove ();
}
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
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.
Is there a way to get this script to pause the text will mouse or keyboard press before moving onto other scripts?
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: 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.
You have done a small mistake. Here's the correct line. You missed the eTypewriterDisplay parameter.
Typewriter.Type (5, 185, 3, 65535, eFontNormal, "Write your text here[[AND WATCH IT TYPE ITSELF", eTypewriter_ShortSpace, eTypewriterDisplay_Overlay, aPop);
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:
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!
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.
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.
Quote from: Noto on Mon 22/06/2020 23:37:36
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.
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:
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);
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)