Is there a way for a keyboard entry when I need an integer from the user?
Especially for this:
https://www.lexaloffle.com/bbs/?tid=141477
On the line of
local playerHand = drawCards(5,cardDeck) |
to which 5 can be modified…
btw can the F keys be overridden to a specific integer? (ie. pressing F12 for an integer of 12)
There are probably more efficient ways of achieving this, but my knowledge on coroutines was weak so I took a look into it. As far as I know if you have an infinite while loop until a valid key is pressed, your game will hang. So you need to get the input within a coroutine that can yield control back to Picotron after each try.
This code works for me and is initiated when cardprompt is not nul. Val contains a valid input from scancodes 49 to 53 on the keyboard (1-5) once it is pressed. Function keys should be the same - just a case of getting their scancodes (F1=58, F12=69)
function _init() cardprompt=true end function getinput(sca,scb) local validinput=nil while not validinput do input=readtext() if input and ord(input)>=sca and ord(input)<=scb then validinput=input end yield() end return validinput end function _update() if cardprompt and not wait then wait=cocreate(getinput) end if wait and costatus(wait) ~= "dead" then temp,val=coresume(wait,49,53) else if cardprompt and val then printh(val) end wait=nil cardprompt=false end end |
In terms on integrating this with your code though, I think you would need your existing code ran as a coroutine (so it doesn't hang Picotron half way through it) and within that, prior to calling playerHand, you can use a while loop with a yield in it like the one in getinput. Not as straight forward as just using Input in BASIC and there may be better ways of doing this like I said.
Thank you for your valuable feedback :3
I’ll try to check it out soon.
[Please log in to post a comment]