This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Stormkrow's profile picture

[Question] Detecting key strokes

Started by Stormkrow, 05 July 2012 - 07:15 PM
Stormkrow #1
Posted 05 July 2012 - 09:15 PM
Hi all,
I've been messing around with keystrokes and cant figure a problem out.
What i wanna do is have a program standardly print out:
>YES<NO
and when the enter is pressed it executes a step or if the user right arrow button is pressed it changes to:
YES>NO<
and if enter is pressed at that stage the program is ended/cancelled

My code is:

a = >YES<NO
b = YES>NO<

local sEvent, param = os.pullEvent("key")
if (sEvent == "key") then
if(param == 205) then
print( b )

if (sEvent == "key") then
if(param == 28) then
shell.run("startup")
else

if (sEvent == "key") then
if(param == 203) then
print(a)
then

if (sEvent == "key") then
if(param == 28) then
function frame()
end
end
end
end

So thats it. I wanna make it so that the program wont effectively end and it can change between the Variable A or B until enter is pressed. Would a loop work? If so how? and then how would i have it so that Variable A is shown standardly and the print for variable will change in the same position where the previous text was if a key stroke is pressed?

Any help is most appreciated:P
Thanks!
MysticT #2
Posted 05 July 2012 - 09:31 PM
There's a tutorial to make a menu like that in the tutorials forum, check it out.
Stormkrow #3
Posted 05 July 2012 - 09:49 PM
Ahhh thanks sorry i didnt see it untill i took a second look:P