Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411275 Posts in 69323 Topics- by 58380 Members - Latest Member: bob1029

March 28, 2024, 05:34:29 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)TutorialsBare-bones Typewriter Text
Pages: [1]
Print
Author Topic: Bare-bones Typewriter Text  (Read 11645 times)
Ant
Guest
« on: October 04, 2010, 01:54:32 AM »

After wanting some typewriter text for my game (so the text gradually appears one letter at a time) I did some searching for a tutorial and quickly found every example I came across was encased in a bunch of RPG 'extras' such as dialogue boxes and multiple answers. All I wanted was the bare-bones and after a bit of trial and error it turns out it's pretty damn easy.

So first of all you'll need to create an object that will be responsible for writing the text on screen. Inside the object's Create event add the following:

Code:
vText = "Show Me"; //This is the text we want to display
iText = 0; //This variable controls how many letters are currently shown (e.g. if iText = 8 then the first 8 letters of vText will be shown
alarm[0] = 1; //Here we set the whole script in motion

In the object's alarm[0] event add the following:

Code:
//We use an if statement here so the alarm stops once the full text is displayed
if iText <= string_length(vText)
{
  iText += 1; //Here we simply add 1 to iText to show one extra letter
  alarm[0] = 10; //This controls how fast the text is written. Increase this if you want it slower
}

And finally we need to show the text, so in the object's Draw event add the following:

Code:
draw_text(x,y,string_copy(vText,1,iText));

And there you have it, job done!

Currently that will only display a single text string, however it's very easy to modify it so you can have a single object control many different strings. The obvious examples for this would be a dialogue or an inventory screen where the text is changed based on the highlighted item. In these cases all you would need to do is change the vText to the new text, reset the iText back to 0 and restart the alarm[0].
« Last Edit: November 11, 2010, 04:38:07 AM by Ant » Logged
antymattar
Level 5
*****


Has earned the contemporary *Banned* medal


View Profile
« Reply #1 on: October 28, 2010, 02:49:15 AM »

THAT... WAS.... EPIC!!!   Hand Point Left Cool  Hand Metal Right

So many projects would have not been abandoned if I had had this.  Cave Story
Logged

man of doom
Level 2
**


It's not Tom and Jerry!


View Profile WWW
« Reply #2 on: October 29, 2010, 03:56:45 AM »

This is awesome, I've been wondering how to do this for ages. Cheers man!
Logged

http://manofdoom.co.uk
Where all my stuff is at!
http://soundcloud.com/man-of-doom
Various musical stuff of mine
phubans
Indier Than Thou
Level 10
*


TIG Mascot


View Profile WWW
« Reply #3 on: November 10, 2010, 08:29:42 PM »

Thanks! This was very light & useful.
Logged

Glyph
Level 10
*****


Relax! It's all a dream! It HAS to be!


View Profile
« Reply #4 on: November 12, 2010, 04:29:01 AM »

Aw, cool! I'd been wondering about how to do this just recently. string_copy works like a charm!
Logged


Raku
Level 10
*****


Dream's Bell


View Profile WWW
« Reply #5 on: November 28, 2010, 02:16:15 AM »

Ah~ thank you so much! This will definitely come in handy!

p.s.

I have another question I forgot to ask, and I don't want to double post.
How do you make it so that it types the words out, erases them, then types another sentence?
(I'm working on a game right now and I'm going to use this for the prologue.)
« Last Edit: November 28, 2010, 02:40:42 AM by Rakugaki-Otoko » Logged

GZ
Level 1
*



View Profile WWW
« Reply #6 on: November 28, 2010, 01:11:24 PM »

Ah~ thank you so much! This will definitely come in handy!

p.s.

I have another question I forgot to ask, and I don't want to double post.
How do you make it so that it types the words out, erases them, then types another sentence?
(I'm working on a game right now and I'm going to use this for the prologue.)
I've made an example integrating this dialog system with a queue system to demonstrate how you can do this:

http://gzstorm.com/gmhelp/Dialog0.gmk

Be sure to check the game information, it has information on the system.
Logged

Raku
Level 10
*****


Dream's Bell


View Profile WWW
« Reply #7 on: November 28, 2010, 01:16:21 PM »

Ah, thank you very much! This teaches me several things. I'll be sure to come back and ask more questions if they arise.
Logged

jkd003
Guest
« Reply #8 on: November 13, 2011, 12:45:47 PM »

I found your tutorial very helpful. Thank you GZ!
Logged
eyeliner
Level 10
*****


I'm afraid of americans...


View Profile
« Reply #9 on: November 25, 2011, 07:53:22 AM »

Thanks, homes. The love of Jesas will invade your insides to keep you warm through the night. I guarantee it. Corny Laugh
Logged

Yeah.
jericito
Level 0
**


i <3 pixels


View Profile WWW
« Reply #10 on: February 16, 2012, 09:04:20 AM »

AWW YEEA! GOOD STUFF!!  Hand Thumbs Up Left Hand Thumbs Up Right
Logged

BomberTREE
Level 9
****



View Profile
« Reply #11 on: April 22, 2012, 02:16:16 PM »

Thank you, very much.  Shocked
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic