Hello again. So, I made an input system in LÖVE 0.8.0 that adds non-UTF-8 chars in texts. It's not exactly a "solution", but it's a "cheaty" way that is working very well. I replace them based on their unicode. For example, for the unicode number of "á", I have the string "[a1]", for "Õ" I have "[O4]", for "ç" I have "[c2]", and so on.
The problem is: I'm trying to convert it to LÖVE 0.9.0, and the way I'm doing it is also working very well (I'm simulating the old love.keypressed(key, unicode) by replacing the unicode with the love.textinput values). Here's an example of it:
The real problem is: how to prevent key repeats in love.textinput? I set love.keyboard.setKeyRepeat to false, but in love.textinput the string keeps repeating, and it is crashing my game! Also, if any possible, how do I get the unicode value of a char? I'm not sure if string.byte is getting it right. I tested it with the old love.keypressed function, and string.byte gives me a different unicode...
[SOLVED] Working with love.textinput
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- HugoBDesigner
- Party member
- Posts: 403
- Joined: Mon Feb 24, 2014 6:54 pm
- Location: Above the Pocket Dimension
- Contact:
[SOLVED] Working with love.textinput
Last edited by HugoBDesigner on Fri Apr 18, 2014 5:26 pm, edited 1 time in total.
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Working with love.textinput
Why would you want unicode, can't use use string.byte() ?
If love.keyboard.setKeyRepeat() didn't do the trick then you could use love.keyreleased() to stop your text function from recording keys like so:
If love.keyboard.setKeyRepeat() didn't do the trick then you could use love.keyreleased() to stop your text function from recording keys like so:
Code: Select all
function love.load()
text = {}
isPressed = false
end
function love.draw()
love.graphics.print(table.concat(text),1,1)
end
function love.keyreleased(k)
isPressed = false
end
function love.textinput(k)
if not isPressed then
text[#text+1] = k
isPressed = true
end
end
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Working with love.textinput
Well for 0.9.0 you gotta use UTF-8.
Help us help you: attach a .love.
- HugoBDesigner
- Party member
- Posts: 403
- Joined: Mon Feb 24, 2014 6:54 pm
- Location: Above the Pocket Dimension
- Contact:
Re: Working with love.textinput
Thanks, you guys! I think I'll stick with Ranguna's solution. I'm making it compatible with both LÖVE 0.8.0 and LÖVE 0.9.0, that's why I needed it like this. Also, I couldn't get UTF-8 to work on my game, so I had to come up with my own way. Also, Ranguna, I already thought of your method, but I didn't realized that it could work. I thought it would still repeat keys if you had more keys being pressed at the same time. Thank you very much!
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: [SOLVED] Working with love.textinput
Actualy with my code you can only press another key once you've released the key you were pressing else it won't record the key, if you want to press another key whilst pressing a different one then love'd have to have two more function: love.textinputPressed() and love.textinputReleased() but it's really wierd that love.keyboard.setKeyRepeat(false) doesn't effect the textinput function.
Any dev out there care to explain why textinput isn't effected by setKeyRepeat ?
Any dev out there care to explain why textinput isn't effected by setKeyRepeat ?
- slime
- Solid Snayke
- Posts: 3132
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: [SOLVED] Working with love.textinput
setKeyRepeat is for key presses. Text input is sort of separate from raw key presses. In fact, different operating systems do different things for textinput when you hold down a key to input text.Ranguna259 wrote:Any dev out there care to explain why textinput isn't effected by setKeyRepeat ?
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: [SOLVED] Working with love.textinput
But is there any way to stop textinput from repeating keys, other from my method that doesn't work for all cases ?
- slime
- Solid Snayke
- Posts: 3132
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: [SOLVED] Working with love.textinput
That's up to the operating system. Keep in mind love.textinput is triggered for any text input, not just key presses which result in text input. As a LÖVE user, you have no idea where the text is coming from.
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: [SOLVED] Working with love.textinput
I see, well Hugo you better find out why your code freezes instead of stopping textinput, there must be some sort of bug in your code
- HugoBDesigner
- Party member
- Posts: 403
- Joined: Mon Feb 24, 2014 6:54 pm
- Location: Above the Pocket Dimension
- Contact:
Re: [SOLVED] Working with love.textinput
Actually, all I had to do was make a variable to get which text input is saved. I made a whole code to get multiple keys being pressed and everything, and it works just as good as it can get (should I post here for future use by others?).
Anyway, the ONLY thing that isn't working is the ability of getting unicodes. Non UTF-8 chars return "195" if I use string.byte. Is there any solution for this?
Anyway, the ONLY thing that isn't working is the ability of getting unicodes. Non UTF-8 chars return "195" if I use string.byte. Is there any solution for this?
Who is online
Users browsing this forum: No registered users and 84 guests