Problems with the escape

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
sen-me
Prole
Posts: 3
Joined: Mon Nov 27, 2017 2:09 pm

Problems with the escape

Post by sen-me »

Hey,
i searched and tried by myself a lot but i can't solve the problem. (sorry for my english so far, iam german)

i try very simple:

Code: Select all

function love.keyreleased(key)
  if key == "escape" then
    -- do something
  end
end
but the code dont execute when i release the esc button, every other button works, but not the escape button.
also when i use keypressed or keyboard.isDown

any idea?
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

Re: Problems with the escape

Post by Sir_Silver »

I copy/pasted your function and it worked perfectly fine for me. I know this is an obvious one, but have you tried putting anything, like a print statement, in your if statement?

Works just fine for me, the last thing I can think of is you either aren't saving your file before running it or you are overwriting that function elsewhere in your code.
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: Problems with the escape

Post by erasio »

Just to make sure, what platform are you using?

Also if you have too much trouble translating what you mean, feel free to just post it on English as best you can, add your German version below and either hope that someone translates it or pm me.

This post is fine. But if you have issues in the future. There are Germans around who are happy to help with the language barrier :)

German version:

Nur um sicher zu gehen, welches Betriebssystem benutzt du?

Und wenn du dir nicht sicher bist, ob du deine Fragen richtig übersetzt hast kannst du gerne deine Frage so gut es geht auf englisch stellen und das ganze auf deutsch nochmal drunter fragen, ähnlich wie ich es mit dem Kommentar hier mache und entweder hoffen, dass jemand der deutsch kann vorbeischaut oder mich direkt anschreiben mit dem link zu deiner frage, damit ich nochmal drüberschauen kann.

Dieser post ist gut genug verständlich. Aber für die Zukunft wenn du Probleme hast.

Es sind einige deutsche Entwickler hier die gerne auch mit der Sprachbarriere helfen :)
sen-me
Prole
Posts: 3
Joined: Mon Nov 27, 2017 2:09 pm

Re: Problems with the escape

Post by sen-me »

Okay thank you for your hint

So, my LOVE Version is 0.10.2
Got Windows 8.1 64bit

I think something blocks the Escape, cuz if i return the result of the pressed key like

Code: Select all

function love.keyreleased(key)
  love.graphics.print(key, 50, 50)
end
than i get every key, just escape is missing
and it also dont work if i make a exe - file (finish the code)

----------

Okay danke für den Tipp

Ich benutze die LOVE Version 0.10.2
Habe Windows 8.1 64bit

Ich glaube irgendwas blockiert die Escape Taste, denn wenn ich die gedrückte Taste ausgebe z.B. wie hier

Code: Select all

function love.keyreleased(key)
  love.graphics.print(key, 50, 50)
end
dann bekomme ich jede Taste angezeigt, nur die Escape wird nie ausgegeben
Auch wenn ich den Code in eine exe-Datei umwandle funktioniert es nicht (Quasi den Code fertig zum Game abschließe)



EDIT:

Omg I'm so sorry, i just opened a game and tried the escape-key and also not working... so i restarted the PC now its working, jesus....
Sorry for the waisted time guys...

---------

Omg tut mir so leid, ich habe gerade einfach mal ein Spiel gestartet und die Escape-Taste dort ausprobiert und sie ging ebenfalls nicht... also habe ich den PC neu gestartet und jetzt gehts auf einmal.... meine Güte....
Tut mir leid für die verschwendete Zeit Leute...
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: Problems with the escape

Post by erasio »

One thing I can imagine going wrong is the printing itself.

Have you tried using print instead of love.graphics.print?

Because the way you are currently printing is not quite compliant with how you ought to draw content and I can imagine weird behavior arising from there.

Try printing key and scancode (the second parameter of keyreleased) and check your console if anything is showing up.

Usually you're meant to only draw within love.draw. To guarantee that you have a consistent gamestate before you draw it. This is enforced by clearing and recentering the canvas before love.draw is called, presenting the finished image afterwards and clearing again the next frame.

Events (such as keypressed or update) are handled before draw. This may just be weird / inconsistent behavior or a bug that anything shows up at all and not the other way around.

Also. In case something else went wrong. You can just try out this code:

Code: Select all

function love.keypressed(key)
	if key == "escape" then
		love.event.quit()
	end
end
This worked on windows 7, love 0.10.2

---

Ich kann mir vorstellen, dass das ausgeben selbst das Problem ist.

Hast du mal probiert print() anstatt love.graphics.print zu benutzen?

So wie du gerade versuchst dir etwas auszugeben ist nicht, wie es vorhergesehen ist und ich kann mir vorstellen, dass es dadurch zu den komischen Ergebnissen kommt.

Versuch einfach mal den key und den scancode (den zweiten Parameter den keyreleased bekommt) und schau in der Konsole nach ob etwas dort auftaucht.

Normalerweise sollte man nur in love.draw etwas malen. Dass bedeutet alle Funktionen, die irgendetwas anzeigen sollen, sollten vom Ablauf her zwischen "love.draw" und dem schließenden "end" passieren.

Wenn du in events wie love.keypressed, love.update oder ähnlichem Zeichnest kann es passieren, dass der gamestate (der Zustand von deinem Game) noch nicht konsistent ist, dinge übermalt werden oder ähnliche blöde dinge passieren).

Löve erzwingt dass sogar, indem es den canvas (dein Fenster) wieder leer macht und mit der Hintergrundfarbe ausmalt. Dann wird love.draw aufgerufen gefolgt von dem präsentieren deines neu erzeugtem Bildes (nur danach wird etwas angezeigt).

Events (wie z.B. keypressed oder update) passieren vor draw. Was du siehst könnte einfach nur komisches verhalten oder ein bug sein, wenn man außerhalb von love.draw malt, und nicht ein bug mit escape.

Du hast davor zwar mit einer Kondition gearbeitet. Aber nur zum sichergehen würde ich dass mal ausprobieren.

Alternativ kannst du auch einfach mal den Code hier ausprobieren:

Code: Select all

function love.keypressed(key)
	if key == "escape" then
		love.event.quit()
	end
end
Das funktioniert bei mir auf Windows 7, love 0.10.2 und beendet einfach das Spiel.
sen-me
Prole
Posts: 3
Joined: Mon Nov 27, 2017 2:09 pm

Re: Problems with the escape

Post by sen-me »

Hmmm, but when i fill up a Canvas and just draw it on the screen in the love.draw section would be okay or?

----

Aber wenn ich ein Canvas erstelle und dann erst in dem love.draw Bereich auf den Bildschirm ausgebe ist das in Ordnung oder?
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: Problems with the escape

Post by erasio »

Yeah that works fine.

Though do keep in mind that creating a canvas per frame is not great for performance and drawing onto the canvas outside of draw means the game state (where everything is, how much hp you have, etc) might change before you end up drawing that (now) out of date information.

This restriction is very deliberately restricting you to do the right thing and keep everything consistent. To save you from yourself.

Because that's one of the worst types of bugs you can have.

Make sure you only prepare things here and don't draw things that actually affect the game.

---

Ja, das klappt problemlos.

Aber behalte im Kopf, dass es nicht gerade gut ist für deine Laufzeit wenn du pro frame einen canvas erstellst. Und außerhalb von draw zu malen bedeutet trotzdem, dass der gamestate (wo alles ist, wie viel HP du hast, etc) auch verändern kann was zu komischen und schwer zu findenden Bugs führen kann.

Löve limitiert dich hier absichtlich. Um dich davor zu schützen.

Stell sicher, dass du nur etwas vorbereitest und nicht tatsächliche Spielelemente malst.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 223 guests