What's best to keep a value for only 1 frame?

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
Eglaios
Prole
Posts: 36
Joined: Mon May 03, 2021 8:45 pm

What's best to keep a value for only 1 frame?

Post by Eglaios »

I'm storing keypresses detected from love.keypressed() into the var "KEY" (for other functions), but only need it for 1 frame, and so I added "KEY = nil" at the end of love.update.

So, is it better to have "KEY = nil" there, or "if KEY then KEY = nil end"? Would there be a simpler or "official" way to keep values only for a single frame?

Thanks!
Currently working on game music...
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: What's best to keep a value for only 1 frame?

Post by zorg »

KEY = nil is fine, nothing bad happens if you nil something that was nil already.

That said, with this method, you can only store one specific key; if you'd press multiple during one frame, only one of them would be saved.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Eglaios
Prole
Posts: 36
Joined: Mon May 03, 2021 8:45 pm

Re: What's best to keep a value for only 1 frame?

Post by Eglaios »

zorg wrote: Tue Oct 05, 2021 5:43 am if you'd press multiple during one frame, only one of them would be saved.
Guess I'll use a table for that then... hopefuly, there're not many places in my game where I have to change this (so far...)
Currently working on game music...
Post Reply

Who is online

Users browsing this forum: No registered users and 60 guests