input text

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
elsalvador
Citizen
Posts: 54
Joined: Thu Oct 24, 2013 1:29 am

input text

Post by elsalvador »

okay here is my question where can i find more information about input text so love can store my variables when i input them as string ???
also to delete letters or to type them here is an example i saw it in another tutorial but didn't give the full details just this

Code: Select all


function love.load()
   g =love.graphics
   name = ""   
end
function love.update()
end
function love.keypressed( key, unicode )
   
   if ( unicode > 31 and unicode < 127 ) then
      name = name .. string.char( unicode )
   end   
end
function love.draw()      
   g.print( "Name: " .. name, 800/2, 600/2 )   
end

wonder whats string.char(unicode)
and why it can only go to 127???? ( unicode > 31 and unicode < 127 )
also how can you delete a letter u didn't want to input like using backspace???

any help will be appreciated or articles or something trying to make a game where the player can input text
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

Re: input text

Post by HugoBDesigner »

Okay, I'll try to simplify it:
The (unicode > 31 and unicode < 127 ) checks if the code of the char you're using fits UTF-8, because those are the only chars Lua supports. It was probably added to avoid crashes on the game. Although I'm not entirely sure if all these chars are included only between 31 and 127. The (string.char(unicode) ) part replaces the unicode by it's relative char. This way you can get the right char (for example, uppercase ones) even if it is in the same key. To erase a char is very simple. Add this to love.keypressed():

Code: Select all

if key == "backspace" then
    if string.len(name) > 0 then
        name = string.sub(name, 1, -2)
    end
end
@HugoBDesigner - Twitter
HugoBDesigner - Blog
User avatar
slime
Solid Snayke
Posts: 3144
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: input text

Post by slime »

You should use the [wiki]love.textinput[/wiki] event callback function for text. The unicode stuff in love.keypressed was removed in LOVE 0.9.0.
elsalvador
Citizen
Posts: 54
Joined: Thu Oct 24, 2013 1:29 am

Re: input text

Post by elsalvador »

ohhhh so its no more valid to use that way?? in 0.9.0 ???
so i am sure its better now? we can uppercase and delete a letter we type hope wiki explains it good ill check it out ...
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests