Hi there.
How would you go about implementing a waitkey function?
With coroutines this should be possible. But how?
-phoku
waitkey()
Re: waitkey()
Can you explain what it'd do?
Re: waitkey()
Sure.
The function does not return until the player presses a key.
The basic assumption is of course, that this is somehow embedded in scheduling framework,
which loads and runs functions as coroutines. A target would a cutscene loader and runner.
Example:
That's a rough example. Also, for example traditionaly rougelikes are written in a more
serial fashion, querying user input in a blocking fashion.
Clear now?
The function does not return until the player presses a key.
The basic assumption is of course, that this is somehow embedded in scheduling framework,
which loads and runs functions as coroutines. A target would a cutscene loader and runner.
Example:
Code: Select all
-- This is a cutscene script.
display_text( "Welcome to the game. Press a key to proceed." )
waitkey()
display_text( "Thanks.")
serial fashion, querying user input in a blocking fashion.
Clear now?
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: waitkey()
Blocking would result in not drawing anymore.
But, how hard would it be to only do something to the game data in the keypressed callback?
But, how hard would it be to only do something to the game data in the keypressed callback?
Re: waitkey()
Not hard, but inconvenient.
I assumed that someone had already written something along those lines.
I attached a very bad version of the waitkey() 'challenge' 8-)
The image is from http://steampunkwallpaper.com/?paged=3, CC derivative.
I assumed that someone had already written something along those lines.
I attached a very bad version of the waitkey() 'challenge' 8-)
The image is from http://steampunkwallpaper.com/?paged=3, CC derivative.
- Attachments
-
- waitkey.love
- (122.57 KiB) Downloaded 318 times
Re: waitkey()
This should work providing time doesn't advance during the draw() function; i.e draw() only draws and does nothing else.
I've uploaded a demo.
Everything in this post is in public domain.
updated function and demo:
I've uploaded a demo.
Everything in this post is in public domain.
updated function and demo:
Code: Select all
function waitKey()
local callbacks={
keypressed=keypressed,
keyreleased=keyreleased,
mousereleased=mousereleased,
mousepressed=mousepressed,
joystickpressed=joystickpressed,
joystickreleased=joystickreleased,
update=update
};
update=function() end;
keyreleased=function() end;
mousereleased=function() end;
mousepressed=function() end;
joystickpressed=function() end;
joystickreleased=function() end;
keypressed=function(key)
update=callbacks.update;
keypressed=callbacks.keypressed;
keyreleased=callbacks.keyreleased;
mousereleased=callbacks.mousereleased;
mousepressed=callbacks.mousepressed;
joystickpressed=callbacks.joystickpressed;
joystickreleased=callbacks.joystickreleased;
if type(waitkeypressed)=="function" then
waitkeypressed(key);
end
end
end
- Attachments
-
- waitkey.zip
- waits key when rectangle at x=100, then adds key number to rectangle's y value.
- (2.35 KiB) Downloaded 318 times
Re: waitkey()
That's not, you know, blocking. Pushing and popping callbacks as a way of handling game state sure is one way ...
Well, I assumed that someone surely had written a system to do this using coroutines,
which I could shamelessly ... learn from. So back to the design board it is, for me.
Thank you for your time.
Well, I assumed that someone surely had written a system to do this using coroutines,
which I could shamelessly ... learn from. So back to the design board it is, for me.
Thank you for your time.
Re: waitkey()
If you wanted cutscenes while waiting for a key press then just add your cutscene code into the empty functions assigned to callbacks inside the waitkey function.phoku wrote:That's not, you know, blocking. Pushing and popping callbacks as a way of handling game state sure is one way ...
Well, I assumed that someone surely had written a system to do this using coroutines,
which I could shamelessly ... learn from. So back to the design board it is, for me.
Thank you for your time.
It's not blocking but I think Im still achieving the same effect.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: waitkey()
Blocking + games = no drawing = bad
Basically all I have to say about it, appleide's solution might be best, because that leaves the draw function working.
Basically all I have to say about it, appleide's solution might be best, because that leaves the draw function working.
Re: waitkey()
*cough*
This is possible with coroutines. I have attached the proof of concept before.
The question was not whether it's possible, but how to do it good :-)
This is possible with coroutines. I have attached the proof of concept before.
The question was not whether it's possible, but how to do it good :-)
- Attachments
-
- waitkey.love
- (122.57 KiB) Downloaded 317 times
Who is online
Users browsing this forum: Ahrefs [Bot] and 0 guests