Hi there, I'm very new to scripting as a whole so please forgive me if i take any liberties.
I'm writing a basic random name generator as an intro to love 2D but i keep recieving the same error about the love.keypressed function.
I'm sure it's something super simple but i've checked the wiki and the forum posts but nothing explains how i might fix it in simple enough terms for me to understand.
Please view the attached .love and assist me with any help you can offer.
cheers,
Attempt to call field 'keypressed'(a nil value) - noob help
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Attempt to call field 'keypressed'(a nil value) - noob help
- Attachments
-
- main.love
- (500 Bytes) Downloaded 165 times
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Attempt to call field 'keypressed'(a nil value) - noob h
Hi, there were several things wrong in your program.
Regards!
- love.keypressed is a callback function, like love.update and love.draw. You should put it on the same level
- It isn't a good idea to use io at all from inside Löve. It isn't guaranteed to work.
- This means that making the user type "quit" is kindof complicated. I've changed that by making the program exit when pressing escape. If you really want to check that the user types "quit", you have to use love.keypress to annotate that he pressed 'q', then 'u', etc in several variables. And reset those variables if he pressed any other keys (for example if he pressed "quuit" it shoudln't quit). As I said, it's kindof complicated
- You were not concatenating strings properly. In Lua, you concatenate using two dots: a .. b . I've fixed that for you
- It's easier if you replace the "insult" variable by a "message" variable, since you seem to want to print both on the same screen space
Regards!
- Attachments
-
- obnoxious-wastrel.love
- (481 Bytes) Downloaded 186 times
When I write def I mean function.
Re: Attempt to call field 'keypressed'(a nil value) - noob h
thanks very much for your help. i appreciate you listing the issues with it aswell rather than just fixing it.
much obliged.
much obliged.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests