How to program entering the nickname?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Shaohao
Prole
Posts: 1
Joined: Wed Jan 12, 2022 9:28 am
Location: Paris
Contact:

How to program entering the nickname?

Post by Shaohao »

Hello!
I am a newbie for LOVE programming but I learn fast I think. But I have a small issue with one thing. At the beginning of my game, I want to ask the player to enter their desired nickname. I'm programming in lua Love2D.
I want a text box to appear: Your Nickname, then the player enters his nickname, and presses enter when they're done.

I can't get it to work.

Thank you.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to program entering the nickname?

Post by zorg »

Hi and welcome to the forums!

You draw the textbox however you want, with just a few rectangles, or whatever.

You get input with the love.textinput callback. It works per-character, so you'll need to append data to a string (and possibly delete a character if backspace is pressed... optionally you can also implement cursor movement with left/right and deleting to the right with the delete key.)

You do need to draw the already existing string as well so the user gets feedback on how much they've typed (a simple love.graphics.print(str) will do the job, with str being where you store the nickname.)

You probably want to stop detecting entered characters when enter/return is pressed, love.keypressed callback is probably the best option for this (and the detection of other non-character inputs as well, like backspace, left, right, delete, ...)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to program entering the nickname?

Post by pgimeno »

Using a GUI library is also an option :) There are some in the Libraries forum, or check https://github.com/love2d-community/awesome-love2d; also see my sig for Gspöt. For a simple edit box like this, Gspöt might suffice.
Post Reply

Who is online

Users browsing this forum: No registered users and 41 guests