• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

User Input with Text Field or Text Box

A

atxgamedesigner

Guest
Hello,

I'm working on a small desktop application and would like to integrate user input through a text field / text box.

Specifically, I'd love to have a large text box - something like notepad.
A multi-line input area for text, where the string will wrap on to the next line once it reaches the edge of the box.
Honestly, I'm not sure how to achieve this.

I feel that I have a fairly solid understanding of how to display and manipulate strings with GML, but this is really taking that knowledge to the next level.
I was considering buying one of the extensions from the marketplace, but decided that I would rather benefit from the gained knowledge in doing it myself (as well as customizing it to fit within my application from the beginning).

If anyone can help point me in the direction of more information on this topic, or perhaps share some conceptual ideas of how this might work, it would be greatly appreciated.

Thanks for your time!
 
A

atxgamedesigner

Guest
Hi Aura,

Thanks for the reply.
This isn't quite what I'm looking for, but its a good place to start - thanks for sharing the link.

Anyone else have some ideas?
 
I

IzzieBlu

Guest
I know I'm super late but this is for people in the future who are in need of help.

Create Event:
Code:
/// Variables
cursorPos = 1 // The position of the caret
inputText = "" // The input line of text
Step Event:
Code:
/// Input
// Variables
var ctext = ""

// Clipboard
if(keyboard_check(vk_control) && keyboard_check(ord("V")) && clipboard_has_text())
{ ctext = clipboard_get_text() }
if(ctext!="" && (keyboard_check_pressed(ord("V")) || keyboard_check_pressed(vk_control)))
{ inputText = string_insert(ctext, inputText, cursorPos) }

// Backspace
if(keyboard_check_pressed(vk_backspace))
{
      inputText = string_delete(inputText, cursorPos-1, 1)
      inputTimer = inputWait
      cursorPos-=1
}
if(keyboard_string != "")
{
      var t = keyboard_string;
      inputText = string_insert(t, inputText, cursorPos)
      cursorPos+string_length(t)
      keyboard_string = ""
}

// Cursor
if(keyboard_check_pressed(vk_left)){ cursorPos-=1 }
if(keyboard_check_pressed(vk_right)){ cursorPos+=1 }
Wherever You're Using the Input Text:
Code:
/// Display Text
// Add the caret into the input text
displayText = string_insert("|", inputText, cursorPos)
// DISPLAY OR USE CODE
// Ex. draw_text(10, 10, displayText)
This is simple enough to work but may need some fiddling if you want numpad keys, some special keys or keys like home, end, insert and delete to work or even making the cursor go to the mouse position. However this does work with clipboard pasteing, typing and backspacing.
Some stuff that will make it look or feel better: blinking caret, backspace having a timer, selecting, mouse click positioning. All of those aren't too hard to implement so consider them.

Hope this helps!
Cheers~
 
Last edited by a moderator:

Deklaration

Member
Hi, sorry. I've been at this forever and the code you posted is kind of similar to how I write my code. I'm very happy to find some help I can understand.
However, I don't really understand
Wherever You're Using the Input Text:
Where should I put this line? I've tried several options and have yet to see any text. If you could explain a bit more just that part, I would be very grateful. I just need some kind of notepad application in my game.


EDIT: Sorry, just figured it out. Thanks for the help!
 
Last edited:

Kezarus

Endless Game Maker
I know I'm super late but this is for people in the future who are in need of help.
Well, I'm gonna try to use this today and see how this plays out. Thanks Izzie! =]

I love Game Maker, but this lack os UI elements drags my dev speed down... Lost a day in drag and drop already... =/
 
Top