Jump to content


Photo
- - - - -

Easy Text Box Example


  • Please log in to reply
119 replies to this topic

#1 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1492 posts
  • Version:GM:Studio

Posted 15 September 2011 - 11:22 PM

  • Title: Text box example
  • Description: A very easy way to make your own dialog box
  • GM Version: :GM81:, GM:S
  • Registered: Yes, but a limited lite version exists
  • File Type: .gm81 | .zip (.gmx inside)
  • File Size: 19 Kb, 3.42 Mb for Studio Version
  • File Link: GM8.1 | Studio | Studio with icon --- 8.1 Lite | Original 8.1 (All on MediaFire)
  • Required Extensions: None
  • Required DLLs: None
Summary

This is a very simple way to make a dialog/text box for a game. Commented for your convenience.

It supports:
  • Scrolling text (appearing a few letters at a time).
  • Multiple messages at once
  • Easily added strings from anywhere
  • Scaled text
  • Skipping to the end of string (rather than waiting the whole time)
  • Following views
  • Sounds for appearing letters
  • Sounds when the message is closed/next message is loaded
  • Freezing everything when there is text visible
  • Separate box for speaker's name *
  • Colourable text *
  • Scripts for easier use *
* Not in Lite or Original 8.1 version
 
Using a queue, the strings are stored and read back in the same order as before. While the text is appearing, the player can skip to the end of the text, and can then remove the message from the queue to display the next one. When the queue is empty, the object becomes invisible, and stops obstructing the vision. It does NOT require placing multiple objects and the strings can be added to the queue at anytime, anywhere!

The Lite version does the same thing, but with an array that holds the messages, and requires more work for longer sequences of messages.
 
The Studio with icon version also includes support for having an icon of the character speaking in the message box, the same way that you would see in RuneScape.
 
To add automatic string wrapping, see here.
For a workaround for sprite_create_from_screen being removed, see here.
To have the text centered see this post.

Edited by thegame, 21 August 2014 - 02:22 AM.

  • 3

#2 icymx

icymx

    Patrick Brett

  • GMC Member
  • 800 posts
  • Version:GM8

Posted 13 October 2011 - 06:41 AM

Nice!
  • 0

#3 Devinit_gD

Devinit_gD

    GMC Member

  • New Member
  • 232 posts

Posted 19 October 2011 - 04:42 AM

This may help my game! I'll edit this post when I try it!
  • 0

#4 loverock125

loverock125

    GMC Member

  • GMC Member
  • 1830 posts
  • Version:GM8.1

Posted 19 October 2011 - 12:23 PM

Could you please fix the link :)
  • 0

#5 Devinit_gD

Devinit_gD

    GMC Member

  • New Member
  • 232 posts

Posted 19 October 2011 - 01:11 PM

Could you please fix the link :)


The Lite Version link works! :)
  • 0

#6 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1492 posts
  • Version:GM:Studio

Posted 19 October 2011 - 07:56 PM

Huh... if you stare at the error screen for a while it works... but I fixed it anyway!
  • 0

#7 icymx

icymx

    Patrick Brett

  • GMC Member
  • 800 posts
  • Version:GM8

Posted 27 October 2011 - 09:42 PM

Nice work!
  • 0

#8 The_Cone_man

The_Cone_man

    GMC Member

  • New Member
  • 17 posts

Posted 08 November 2011 - 01:53 AM

for some unknown reason i cant get my first speech thing to show. it just skips to the next room. i have even copied the exact coding ver beta and this still happens...no clue as to why, i also cant figure out how to set more variables for an object to speak but just a different dialogue than what was previously said in the room before. if anyone could help i would greatly appreciate it.
edit: spelling mistake

Edited by The_Cone_man, 08 November 2011 - 01:54 AM.

  • 0

#9 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1492 posts
  • Version:GM:Studio

Posted 17 November 2011 - 12:07 PM

Make it work with views because it is useless other wise as a lot of games with this have views...

Did it! Enjoy!
  • 0

#10 _240773

_240773

    GMC Member

  • New Member
  • 2 posts

Posted 24 November 2011 - 04:47 AM

This is great :) Nice work. But how do you pause everything else like the message command does? Anyone know the code? I dont want monsters running around my characters while they are talking to one another, I just want the focus to be on the dialog.

Edited by _240773, 26 November 2011 - 04:20 AM.

  • 0

#11 uebo7

uebo7

    GMC Member

  • New Member
  • 19 posts
  • Version:GM8

Posted 21 December 2011 - 01:36 AM

How do you set the size of the text? On your example game, it's very small, but on my game it appears very large. Is it relative to the room size or something?
  • 0

#12 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1492 posts
  • Version:GM:Studio

Posted 22 December 2011 - 12:26 PM

Set your font to a different size in the font editor, or scale the text in some way. It's not relative to the room size, but to the zoomed-in-ness from your view
  • 0

#13 Bcm27

Bcm27

    GMC Member

  • New Member
  • 333 posts
  • Version:GM8

Posted 02 January 2012 - 11:29 PM

Mind if I comment? I'm saving this to my content thing. :D
  • 0

#14 DudeGuy676

DudeGuy676

    GMC Member

  • New Member
  • 47 posts
  • Version:GM:Studio

Posted 06 January 2012 - 04:26 AM

Could I use this in my game MageStones? I'll put you in the creditz
http://sandbox.yoyog...magestones-v1-2

Edited by DudeGuy676, 06 January 2012 - 04:27 AM.

  • 0

#15 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1492 posts
  • Version:GM:Studio

Posted 06 January 2012 - 02:25 PM

Go ahead! That's what I made it for... :)
  • 0

#16 Devinit_gD

Devinit_gD

    GMC Member

  • New Member
  • 232 posts

Posted 06 January 2012 - 07:55 PM

I like how I got this post popular again. I feel good. C:
  • 0

#17 Bcm27

Bcm27

    GMC Member

  • New Member
  • 333 posts
  • Version:GM8

Posted 06 January 2012 - 08:23 PM

Lol, actually. I encountered a problem.

/* NOTE:
Make sure the box is NOT visible and IS persistent
Put ONE text box in the first room 
*/

image_speed=0.05; //Set the image to not flash too fast
//Create a queue to contain all the texts
globalvar text;
text=ds_queue_create();
drawstr="";

//Set the string position to make the text scroll nicely
pos=0;

On the Example- Textbox gmk8 file this globalvar text; does not come up as a error. But when I try and use it.
It shows up as a error.

Posted Image

I copied the code and all the objects and sprites. Anybody got a clue?
  • 0

#18 Sirosky

Sirosky

    GMC Member

  • GMC Member
  • 1502 posts
  • Version:GM:Studio

Posted 07 January 2012 - 01:12 AM

It looks nice, though the text box lags behind with views but I'm sure this problem will be easily alleviated with a bit of code.
  • 0

#19 Bcm27

Bcm27

    GMC Member

  • New Member
  • 333 posts
  • Version:GM8

Posted 07 January 2012 - 03:28 AM

Anybody got a answer to my question. :D
  • 0

#20 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1492 posts
  • Version:GM:Studio

Posted 07 January 2012 - 01:35 PM

Do you have another variable in your game called 'text'? That may cause the problem...
  • 0

#21 Bcm27

Bcm27

    GMC Member

  • New Member
  • 333 posts
  • Version:GM8

Posted 07 January 2012 - 10:45 PM

No, I dont. Im sure of it.
  • 0

#22 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1492 posts
  • Version:GM:Studio

Posted 08 January 2012 - 12:51 AM

OH! You must have a resources named text, I am sure of this because the colour is wrong... it should be blue not the light brown
  • 0

#23 Bcm27

Bcm27

    GMC Member

  • New Member
  • 333 posts
  • Version:GM8

Posted 08 January 2012 - 08:56 PM

Ah, that's it. :D I do have resource named text, I'll change that right now. :D


==edit==
I did have a resource named text but that wasn't the problem. I had a object names text. So if anyone else comes across this problem, tell them to change the name of there text object. :D

Edited by Bcm27, 09 January 2012 - 09:35 PM.

  • 0

#24 Bcm27

Bcm27

    GMC Member

  • New Member
  • 333 posts
  • Version:GM8

Posted 09 January 2012 - 11:23 PM

Ok, now heres a question for you. How do you change the font size? its alittle to big for my current game window.
  • 0

#25 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1492 posts
  • Version:GM:Studio

Posted 10 January 2012 - 12:13 AM

To rescale the text, change the two parts that are # from objTextbox's Draw event
if(drawstr!="") {
    //Draw the text, scrolling across the box
    draw_set_font(-1);
    draw_set_color(c_black);
    draw_self();
    cstr=string_copy(drawstr,1,pos);
    draw_text_ext_transformed(x+16,y+16,cstr,-1,-1,#,#,0); // <-- Change # to rescale text
    pos+=1.5;
}
1 is the current value, which is the original size. 2 would be double the size, and 0.5 would be half.

Edited by thegame, 10 January 2012 - 12:13 AM.

  • 0

#26 Bcm27

Bcm27

    GMC Member

  • New Member
  • 333 posts
  • Version:GM8

Posted 10 January 2012 - 01:04 AM

Alright, thanks.

==edit==
Im still new to gm, so I'm still using drag and drop, although I hope to move onto gml soon enough. :D


===edit===
wait, I am very stupid I think I see what I did wrong. :D

===edit===
Ok, I saw what I did wrong, :D I only glanced at the code. :D Thanks for the help.

Edited by Bcm27, 10 January 2012 - 01:08 AM.

  • 0

#27 Adam Wolf

Adam Wolf

    GMC Member

  • New Member
  • 2 posts

Posted 22 January 2012 - 05:47 PM

Hey, I really like this example and want to adapt it to my small game I'm working on but I'm having difficulty adding sound just while the text is displaying. I tried playing sound while 'drawstr' isn't empty but it plays the entire time the textbox is active.

Has anybody successfully added sound to this yet?

Thanks in advance!
  • 0

#28 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1492 posts
  • Version:GM:Studio

Posted 22 January 2012 - 06:01 PM

I'll see what I can do - its a good idea for sure
By sound, you mean like... the beepbeepbeep for each letter that shows up right?
And a click or something when the next message comes up?

Edit: DONE! How is it?

Edited by thegame, 22 January 2012 - 06:22 PM.

  • 0

#29 Adam Wolf

Adam Wolf

    GMC Member

  • New Member
  • 2 posts

Posted 22 January 2012 - 07:53 PM

I'll see what I can do - its a good idea for sure
By sound, you mean like... the beepbeepbeep for each letter that shows up right?
And a click or something when the next message comes up?

Edit: DONE! How is it?


you're awesome. checking it out now.

edit: confirmed. you are awesome. works perfect.

i was just trying if(drawstr!=""). i don't really understand what/how you're checking cstr in that if statement though.

Edited by Adam Wolf, 22 January 2012 - 08:04 PM.

  • 0

#30 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1492 posts
  • Version:GM:Studio

Posted 22 January 2012 - 08:07 PM

I am checking to see if the string that is written is the same as the string that is to be drawn... I don't know if it had to be that complicated but that's what it does...
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users