Jump to content


Photo

Textboxes: Editable Text In Your Games


  • Please log in to reply
50 replies to this topic

#1 Davve

Davve

    GMC Member

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

Posted 24 August 2013 - 04:46 PM

Textboxes
 
Use this to draw text on the screen that, unlike draw_text, can be selected and edited.
The text is confined inside an invisible box with the wished dimensions. Use draw_rectangle or sprites to design your own boxes around the text. Word-wrapping makes sure that words never exceed the box and you can make it limited to one line and much more.
 
Download (.zip) for GM8, GM8.1, GM:Studio, contains the two scripts and three rooms with examples of use.

12-1.png

12-2.png


 
Installation and use
  • Copy the textbox_create and textbox_draw scripts into your game.
  • Create an empty object called obj_textbox.
  • Use textbox_create to make instances of the textbox object, change parameters then use the instance IDs in textbox_draw.
Controls
 
Click and drag: Character select
Double click: Word select
Ctrl+X/Right click menu*: Cut
Ctrl+C/Right click menu*: Copy
Ctrl+V/Right click menu*: Paste
Ctrl+A/Right click menu*: Select all
Backspace: Remove last character
Delete: Remove next character
Mouse wheel: Scroll up/down
Arrow keys: Move marker
Shift+arrow keys: Move selection start/end
Shift+click: Set selection start/end
 
*The right click menu is unavailable in GM:Studio. R.I.P. show_menu.

Edited by Davve, 18 October 2015 - 02:46 PM.

  • 29

#2 AIex

AIex

    Online programmer

  • GMC Member
  • 136 posts
  • Version:GM8

Posted 24 August 2013 - 04:52 PM

It's kinda like an old script you had on your site, I forgot what it was called, but that one was really laggy.

 

Good script! I like your text scripts a lot.


Edited by Terexzes, 24 August 2013 - 04:52 PM.

  • 0

SbfzcTq.png


#3 Trasoside

Trasoside

    GMC Member

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

Posted 24 August 2013 - 05:02 PM

won't work on gm studio D:


  • 0

rep_up.png If I helped you  :)

some Stuffs I made in GameMaker:

<SPRIVOM - Skeletal Animation Tool> <SunFury MapCreator> <LD Entries>

You can also find me at:

<BlogSpot> <YouTube> <PixelJoint> <DeviantArt> <Twitter>


#4 Davve

Davve

    GMC Member

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

Posted 24 August 2013 - 05:04 PM

It's kinda like an old script you had on your site, I forgot what it was called, but that one was really laggy.
 
Good script! I like your text scripts a lot.

Thanks, it's a complete rewrite of the old one. This has pretty much been in development since 2010, I just couldn't be bothered to finish it until a few days ago. :P
 

won't work on gm studio D:

I was actually talking to a friend about how this might not work in the new compiler, which I don't have access to. What error do you get?

Edited by Davve, 24 August 2013 - 05:07 PM.

  • 0

#5 Trasoside

Trasoside

    GMC Member

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

Posted 24 August 2013 - 05:09 PM

first of all, in studio, you must use all the arguments, otherwise you'll get an error
so i filled everything with 0

 

then when i started selecting the text, this apeard:
 

 


 
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Draw Event
for object obj_example_1:
 
DoSet :: Invalid comparison type
 at gml_Script_draw_text_edit (line 209) -         if (filterchars!="" && inserttext!="") {
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_draw_text_edit (line 0)
called from - gml_Object_obj_example_1_Draw_0 (line 6) -         EXT: draw_text_edit(id, def, x1, y1, x2, y2, singleline, readonly, maxchars, filterchars, replacechar, selectedtextcolor, selectioncolor)

 

 

i fixed it by doing string()

but now when selecting text, i see black selection :S

 +can't show_menu in gms 

 

and i just figured out that i can't type anything xD

only backspacee works


Edited by Trasoside, 24 August 2013 - 05:14 PM.

  • 0

rep_up.png If I helped you  :)

some Stuffs I made in GameMaker:

<SPRIVOM - Skeletal Animation Tool> <SunFury MapCreator> <LD Entries>

You can also find me at:

<BlogSpot> <YouTube> <PixelJoint> <DeviantArt> <Twitter>


#6 Davve

Davve

    GMC Member

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

Posted 24 August 2013 - 05:18 PM

i fixed it by doing string()
but now when selecting text, i see black selection :S
 +can't show_menu in gms 
 
and i just figured out that i can't type anything xD
only backspacee works

What version are you on? It works fine in 1.1.1044, and I can't seem to find any options to update in Studio. Working on fixing it...

Edited by Davve, 24 August 2013 - 05:20 PM.

  • 0

#7 Trasoside

Trasoside

    GMC Member

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

Posted 24 August 2013 - 05:20 PM

 

i fixed it by doing string()
but now when selecting text, i see black selection :S
 +can't show_menu in gms 
 
and i just figured out that i can't type anything xD
only backspacee works

What version are you on? It works fine in 1.1.1044, and I can't seem to find any options to update in Studio.

 

master collection v1.2.1130


  • 0

rep_up.png If I helped you  :)

some Stuffs I made in GameMaker:

<SPRIVOM - Skeletal Animation Tool> <SunFury MapCreator> <LD Entries>

You can also find me at:

<BlogSpot> <YouTube> <PixelJoint> <DeviantArt> <Twitter>


#8 Davve

Davve

    GMC Member

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

Posted 24 August 2013 - 06:04 PM

The script should now work for GM:Studio versions up to and including 1.2. PM me if anyone is still having issues.
  • 0

#9 mrsmes

mrsmes

    GMC Member

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

Posted 06 September 2013 - 08:21 AM

one more thing can it allow you to change the font to any windows font at any due time of running the game/application?


  • 0

Assuming I helped you out in a questions and answers topic won't you return the favour by helping me with one my coding problems, or recommend some one who can chat to me over pms about helping and how to overcome my obstacles, after all lets just say I did help you or them or many people with similar problems, in that topic.

Here i have a topic for those of you struggling with type writer text and mugshots in your games especially if it is a rpg see the link below for more info

http://gmc.yoyogames...howtopic=619103

almost no code needed, only uses two events.

click here for the l8est version of feed the alien pizza, it has some major polished up features.


#10 Big J

Big J

    GMC Member

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

Posted 12 September 2013 - 10:46 AM

Doesn't work in GM8, just says "Unexpected error occurred when running the game". Works fine in GM 8.1 though. Neat.

 

I figured it out: invalid font ranges defined. I'm not sure why you put such strange values into the starting range of the fonts or why GM even allows that.


Edited by Big J, 12 September 2013 - 10:51 AM.

  • 1

Get your GM 8.1 Anti-Aliasing here!

2712265.png

http://www.youtube.com/Sporkinator


#11 Shadowrend

Shadowrend

    Master of Shadows

  • GMC Member
  • 3071 posts
  • Version:GM8

Posted 19 September 2013 - 06:23 PM

Looks nice and it's a bit simpler than mine. Mind if I use this in my GMWinUI, I'll credit you for the script?


  • 0

#12 Davve

Davve

    GMC Member

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

Posted 19 September 2013 - 06:36 PM

Looks nice and it's a bit simpler than mine. Mind if I use this in my GMWinUI, I'll credit you for the script?

Go ahead :)
  • 0

#13 Davve

Davve

    GMC Member

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

Posted 19 September 2013 - 11:27 PM

Fixed .gmk

Also, you can now set the global text_str[id] to a string and the text with that id will have its text changed.


  • 0

#14 LurchBrick

LurchBrick

    GMC Member

  • GMC Member
  • 141 posts

Posted 20 September 2013 - 09:46 AM

Great script and easy to use.

 

I was wondering if you could please explain why you have used so many global variables in the script?


  • 0

#15 Davve

Davve

    GMC Member

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

Posted 20 September 2013 - 09:57 AM

Great script and easy to use.

 

I was wondering if you could please explain why you have used so many global variables in the script?

So that the script is global and all the texts can be accessed through all the rooms and objects.


  • 0

#16 LurchBrick

LurchBrick

    GMC Member

  • GMC Member
  • 141 posts

Posted 12 October 2013 - 03:01 AM

I'm having some issues with the max characters option and width of the displayed text.

 

The font I am using is not a uniform width for each letter, i.e. a "W" character uses more width space than the "a" character. I wish to limit the amount of text the user can enter to fit inside a single line textbox field. Currently, if I set the max characters to 50 and if the user types with large width characters, the text moves within the box and the user cannot see what they've typed at the start of the line. Conversely, if I set the max characters to a lower number and if the user types with small width characters, the text displays fully within the box but there is a large space where it appears they should be able to type. This is not pleasing from a uniform UI perspective.

 

Do you have any hints on a way to adapt the script to use a variable amount of characters that can fit in a visibly defined space?


  • 0

#17 Davve

Davve

    GMC Member

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

Posted 12 October 2013 - 11:02 AM



...the text moves within the box and the user cannot see what they've typed at the start of the line.

 

They can, if they click and drag the selected text or use the arrow keys.

 

 

Do you have any hints on a way to adapt the script to use a variable amount of characters that can fit in a visibly defined space?

 

Certainly, add this after line 313 in the GM8.1 version. If you're using another version, add it to the line above if (inserttext!="") {

while (singleline && string_width(text_line[i,0])+string_width(inserttext)>w && inserttext!="")
    inserttext=string_copy(inserttext,1,string_length(inserttext)-1)

This will cut off any characters outside of the box, including pasted text.


  • 0

#18 LurchBrick

LurchBrick

    GMC Member

  • GMC Member
  • 141 posts

Posted 12 October 2013 - 01:04 PM

Thanks Davve. Worked a treat.


  • 0

#19 LurchBrick

LurchBrick

    GMC Member

  • GMC Member
  • 141 posts

Posted 18 October 2013 - 03:11 AM

Sorry to bother you again Davve.

 

I've tried to implement similar code to what you gave me above but for keeping multi line text within a rectangle in the vertical dimension. I've tried using code with the string_height and the text_lines[] array variables without much luck. I was hoping you could please provide a solution.

 

Cheers


  • 0

#20 Davve

Davve

    GMC Member

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

Posted 18 October 2013 - 08:09 AM

Sorry to bother you again Davve.

 

I've tried to implement similar code to what you gave me above but for keeping multi line text within a rectangle in the vertical dimension.

 

Why not just implement a scrollbar? I made one here: http://www.stuffbyda...ples/scrollbars, just set it to the text_start[ID] value.


  • 0

#21 LurchBrick

LurchBrick

    GMC Member

  • GMC Member
  • 141 posts

Posted 19 October 2013 - 01:03 AM

I've actually already used those scroll bars in another part of my game. :)

 

Some background might help explain why I don't want to use scrollbars in this instance. My game is based on a card mechanic, similar to Magic the Gathering type games. While there are a set number of provided default cards, the game allows the player to make their own unique cards which they can assign powers to.

 

Therefore, what I'm trying to achieve with this part of my game is to create a card description textbox that is located on the card for the player to edit. That is why I want to limit the text to what can just fit in the space allocated on the card.


  • 0

#22 Craig Davidson

Craig Davidson

    GMC Member

  • GMC Member
  • 159 posts

Posted 06 November 2013 - 05:31 AM

I wonder, how can I use this so that as I type and edit the words, it gets copied to a separate variable? I really need help with this.


Edited by Craig Davidson, 06 November 2013 - 05:31 AM.

  • 0

#23 Davve

Davve

    GMC Member

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

Posted 06 November 2013 - 06:45 AM

I wonder, how can I use this so that as I type and edit the words, it gets copied to a separate variable? I really need help with this.

 

myString = draw_text_edit(...)


  • 0

#24 Craig Davidson

Craig Davidson

    GMC Member

  • GMC Member
  • 159 posts

Posted 07 November 2013 - 12:36 AM

 

I wonder, how can I use this so that as I type and edit the words, it gets copied to a separate variable? I really need help with this.

 

myString = draw_text_edit(...)

 

Thank you!


  • 0

#25 - Windows7 -

- Windows7 -

    GMC Member

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

Posted 16 December 2013 - 03:55 PM

Is text_line[...] read-only variable?

 

I can't assign something...

 

text_line[0,0] = 'Hello'     // Doesn't work

text_line[0,0] = MyVariable    // Doesn't work

text_line[0.0] = ini_read_string('Line','1','aaa')    // Doesn't work


  • 0

#26 Davve

Davve

    GMC Member

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

Posted 16 December 2013 - 04:00 PM

Is text_line[...] read-only variable?

 

I can't assign something...

 

text_line[0,0] = 'Hello'     // Doesn't work

text_line[0,0] = MyVariable    // Doesn't work

text_line[0.0] = ini_read_string('Line','1','aaa')    // Doesn't work

 

text_line is read only.

Change text_str[ID] and the textbox will update.

text_str[ID] = 'Hello ' + string(MyVariable)

For multiple lines, use chr(10)

text_str[ID] = 'This script is #1 ' + chr(10) + string(pi)

 

will become

This script is #1!
3.14

  • 0

#27 - Windows7 -

- Windows7 -

    GMC Member

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

Posted 16 December 2013 - 04:18 PM

Great, Thank you  :)


  • 0

#28 jon sploder

jon sploder

    GMC Member

  • GMC Member
  • 919 posts

Posted 16 December 2013 - 10:00 PM

This is absolutely fantastic, you're a great man for writing this up. Exceptional.


  • 2

#29 rater193

rater193

    GMC Member

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

Posted 10 May 2014 - 09:21 PM

I was wandering if i could implement this with my current gui engine? i will give credit ofcource


  • 0

Click this to find out what you are!

Posted Image


#30 Davve

Davve

    GMC Member

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

Posted 11 May 2014 - 10:20 PM

I've greatly upgraded this today. The draw script now only takes an object id and the dimensions of the box. The object is an empty dummy that stores the info about the textbox. This resulted in cleaner code, less globals and increased user-friendliness.

 

You can also make textboxes auto-selected upon focusing them.

 

Everyone can use and modify (if you're a maniac) this freely, giving credit would be appreciated but I won't sue you if you don't.


Edited by Davve, 11 May 2014 - 10:23 PM.

  • 6

#31 Hashirama Senju

Hashirama Senju

    GMC Member

  • New Member
  • 17 posts
  • Version:GM8.1

Posted 28 May 2014 - 02:39 PM

Hello Davve,

I think something is wrong, either with me or with your script.

 

I just made another object in your example's room 3 and wrote this code in it's step event.

Self.x = 635+obj_example3.text_age.text;

Why is this not working?

The names I used in the above code maybe different because I wrote it from memory,but concept should be correct.

Why is it giving an error? " Something like Not the correct operator used with +"


Edited by Hashirama Senju, 28 May 2014 - 02:39 PM.

  • 0

#32 Davve

Davve

    GMC Member

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

Posted 28 May 2014 - 05:48 PM

Why is this not working?

The names I used in the above code maybe different because I wrote it from memory,but concept should be correct.

Why is it giving an error? " Something like Not the correct operator used with +"

 

Hi, you cannot directly add numbers to strings, use the real(str) function as so:

Self.x = 635+real(obj_example3.text_age.text);

Remember to set the filter_chars to "0123456789" so the user can't type anything that could cause an error. :)


  • 1

#33 Hashirama Senju

Hashirama Senju

    GMC Member

  • New Member
  • 17 posts
  • Version:GM8.1

Posted 28 May 2014 - 07:09 PM

Hi, you cannot directly add numbers to strings, use the real(str) function as so:

Self.x = 635+real(obj_example3.text_age.text);

Remember to set the filter_chars to "0123456789" so the user can't type anything that could cause an error. :)

 

Thanks.

Your textbox is amazing. It saved me so much hard work :)


  • 1

#34 bwalker

bwalker

    GMC Member

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

Posted 09 June 2014 - 11:30 PM

Thanks for the script! Exactly what i needed. I'm new to programming. I did not notice any simple numbers to manipulate to change the text box size.

So, how can I adjust the text box size?

 

Since i cannot erase this post... I'll answer that: it's in the draw event of the object text example.

I thought it was in the scripts but not so.

 

Thx again!


Edited by bwalker, 09 June 2014 - 11:41 PM.

  • 0

#35 MrJackSparrow2

MrJackSparrow2

    GMC Member

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

Posted 13 June 2014 - 06:25 AM

Davve, this script is excellent! I know this is REALLY asking a lot, but what do you think about multiple colors/font styles in a single text box? Something like using bbcode (or your own version of it) to allow font coloring? It'd be great if you could include coloring (maybe even bold/italic?)! I can dream, right?


  • 1

#36 Indecom4000

Indecom4000

    GMC Member

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

Posted 17 June 2014 - 07:34 AM

Davve! Your ****'s awesome. just sayin.


  • 0

LD-Logo-sml.png


#37 mrsmes

mrsmes

    GMC Member

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

Posted 18 June 2014 - 03:53 AM

Will this work gmstudio professional and standard you see i am thinking about giving my brother sam a free copy of standard...

Also if this works i may even consider using it in my project "Twisted Reality Art Of War" with the regristration and login and player character customization screen and for a chat window.

Oh one more thing what happened to the download link for this extension, and example on how to use it?

Edit nvm my fault i was not looking hard enough i found it.

 

Ok so it does what i want but could you make a more simple simplified login and register example or atleast send me a link to a topic where i can find one, if you make that part of my engine i will add your name to the credits of my game and make you a admin for it as well as a moderator and i will make the character customization system.


Edited by mrsmes, 18 June 2014 - 06:10 AM.

  • 0

Assuming I helped you out in a questions and answers topic won't you return the favour by helping me with one my coding problems, or recommend some one who can chat to me over pms about helping and how to overcome my obstacles, after all lets just say I did help you or them or many people with similar problems, in that topic.

Here i have a topic for those of you struggling with type writer text and mugshots in your games especially if it is a rpg see the link below for more info

http://gmc.yoyogames...howtopic=619103

almost no code needed, only uses two events.

click here for the l8est version of feed the alien pizza, it has some major polished up features.


#38 Zerb Games

Zerb Games

    GMC Member

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

Posted 16 July 2014 - 10:01 PM

Hey Mine-imator guy! ;)


  • 0

-Stay Royal


#39 ParodyKnaveBob

ParodyKnaveBob

    theUndiscovered

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

Posted 22 July 2014 - 06:51 AM

Concerning Studio dropping the game-freezing show_menu() function, here's a thought. Just tonight, I saw that NPC published a "Simple Drop Down Menu" Asset to the YYG Marketplace (currently Early-Access only). It's free at the moment. Perhaps you (Davve) could have a look-see at that and make some kind of licensing deal with NPC to incorporate the SDDM? Considering you both offer this particular stuff for free, I predict that'll go over well.

(Disclaimers: I am an unconnected third party to both Davve and NPC. I have not actually used either of their stuff yet.)

Regards, $:^ ]
  • 0
theUndiscovered ~ Brandon W. Horton ~ ParodyKnaveBob ~ $:^ J

#40 supinyo

supinyo

    GMC Member

  • New Member
  • 12 posts

Posted 02 August 2014 - 01:55 PM

Many Thank , Very useful for me

 

:woot:  :thumbsup:


  • 0

I love Game maker


#41 Istuk5

Istuk5

    Zombie apocalypse

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

Posted 21 September 2014 - 09:24 PM

Is there any way I can get current line?


  • 0

One thing I like to say:

"There is only one place you can call home, there is only one woman you can love. Whole world is too big for one person, but still there is always at least one person who wants whole world. Greed will destroy us"


#42 Davve

Davve

    GMC Member

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

Posted 23 September 2014 - 09:24 PM

Is there any way I can get current line?

 

Yes, try one of these globalvars:

 

textbox_select_startline
textbox_select_endline
textbox_select_mouseline
textbox_select_clickline

  • 2

#43 MrJackSparrow2

MrJackSparrow2

    GMC Member

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

Posted 09 October 2014 - 01:07 AM

What's the license for this? Just curious about using it in a commercial product.
  • 0

#44 Davve

Davve

    GMC Member

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

Posted 09 October 2014 - 05:33 AM

What's the license for this? Just curious about using it in a commercial product.

 

You're allowed to use this in any project, commercial or not. Getting some credit would be appreciated.


  • 2

#45 rockgames

rockgames

    GMC Member

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

Posted 20 October 2014 - 02:50 PM

This is great man! Good work! So far (from what I have seen) 5/5 stars. I will recommend this to my students.


  • 0

#46 eyeballs

eyeballs

    GMC Member

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

Posted 08 January 2015 - 07:34 AM

This is awesome! I was working on my own text-input system, so I appreciate how challenging it can be to get everything to work right. With that said, I did discover a bug in the system.

 

If you type space when you're at the end of a line, type some text, and hit backspace to delete where the space-character would be, text starts disappearing, new text doesn't show up, and the text-cursor (Marker) can go off screen.

 

Davve, I'm also curious about the screenshot on your original post. Did you procedurally generate that text?

 

Btw: I might use your scripts in my programs, and I will definitely credit you.


Edited by eyeballs, 08 January 2015 - 07:36 AM.

  • 0

#47 mza1979m

mza1979m

    GMC Member

  • GMC Member
  • 41 posts

Posted 26 January 2015 - 11:45 PM

Is this something that can be used on mobile devices?


  • 0

#48 Davve

Davve

    GMC Member

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

Posted 27 January 2015 - 09:58 AM

 

If you type space when you're at the end of a line, type some text, and hit backspace to delete where the space-character would be, text starts disappearing, new text doesn't show up, and the text-cursor (Marker) can go off screen.

I'll look into this when I get the time.

 

Davve, I'm also curious about the screenshot on your original post. Did you procedurally generate that text?

I used some random text generator I found by Googling.

 

Is this something that can be used on mobile devices?

You'll have to modify keyboard_string to make this work on mobile devices.


  • 0

#49 hbphuc

hbphuc

    GMC Member

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

Posted 22 April 2015 - 02:12 PM

Good job!

 

Thank you very much Davve.


  • 0

#50 KiTheif

KiTheif

    Gotta Dev

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

Posted 23 August 2015 - 07:47 PM

Hey there Davve, awesome work! All it needs is undo/redo functionality to be perfect  ^_^ (besides the bug mentioned above)

 

For anyone who wants to use the textbox with game makers GUI, you can edit all the mouse positions in textbox_draw to check the positions via-gui.

Replace these with those.
mouse_x -> device_mouse_x_to_gui(0)
mouse_y -> device_mouse_y_to_gui(0)

Edited by KiTheif, 04 September 2015 - 05:25 AM.

  • 0