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 .
Kookerus
Prole
Posts: 39 Joined: Sat Jun 28, 2014 4:33 am
Post
by Kookerus » Mon Jul 21, 2014 1:53 am
I'm trying to make a program wher the user just types in a box, and if backspace is pressed, the last character is deleted. I have the code working, but the second time bacekspace is pressed, it won't delete the last character.
Code: Select all
function love.load()
intro = "Type away! -- \n"
text = ""
numTimes = 0
end
function love.textinput(t)
text = text .. t
numTimes = numTimes + 1
end
function love.keypressed(key)
if key == "backspace" then
text = string.sub(text, 1, numTimes - 1)
end
end
function love.draw()
love.graphics.printf(text, 0, 0, love.graphics.getWidth())
end
Can anyone help me?
Kookerus
Prole
Posts: 39 Joined: Sat Jun 28, 2014 4:33 am
Post
by Kookerus » Mon Jul 21, 2014 2:04 am
Never mind. I realized I forgot to decrease the "numTimes" variable. Changed it and it worked like a charm!
Positive07
Party member
Posts: 1014 Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina
Post
by Positive07 » Mon Jul 21, 2014 4:39 am
Okey just so that you can learn some things:
you could use something like
notice that text:sub is the same as string.sub(text...)
also you can do
text length should return the number of characters in text
or instead use something like
Since negative numbers count from the last character + 1 (because it is inclusive)
Have fun with lua!!
for i, person
in ipairs (everybody)
do
[tab] if not person.obey
then person:setObey(
true )
end
end
love.system.openURL(
github.com/pablomayobre )
Kookerus
Prole
Posts: 39 Joined: Sat Jun 28, 2014 4:33 am
Post
by Kookerus » Mon Jul 21, 2014 8:06 pm
Positive07 wrote: Okey just so that you can learn some things:
you could use something like
notice that text:sub is the same as string.sub(text...)
also you can do
text length should return the number of characters in text
or instead use something like
Since negative numbers count from the last character + 1 (because it is inclusive)
Have fun with lua!!
Thank you so much! I've never used lua before, and it's quite a bit different than python
Positive07
Party member
Posts: 1014 Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina
Post
by Positive07 » Tue Jul 22, 2014 6:03 pm
Well... I have never used python (I used it once but just a little) so I will call you when I need to
for i, person
in ipairs (everybody)
do
[tab] if not person.obey
then person:setObey(
true )
end
end
love.system.openURL(
github.com/pablomayobre )
Kookerus
Prole
Posts: 39 Joined: Sat Jun 28, 2014 4:33 am
Post
by Kookerus » Tue Jul 22, 2014 8:09 pm
Sounds like a plan!
Users browsing this forum: Ahrefs [Bot] and 77 guests