Posted 13 July 2015 - 05:53 PM
So the below code is a new rules script i'm making based upon the player pressing a number from 1 to 3 for the answer. This code worked fine for a small while but for some reason when i edited something very minor that shouldn't have effected it (the stuff that happens after the else statement) it failed to recognise a keypress at all.
function kp(n)
while true do
local event, keypress = os.pullEvent( "key" )
keys.getName(keypress)
end
term.setCursorPos(22,11)
if keypress == n then
term.setTextColor(colors.green)
print("Correct!")
os.sleep(2)
term.clear()
else
term.setTextColor(colors.red)
os.sleep(5)
print("Incorrect, please try again")
end
end
function y()
term.setTextColor(colors.yellow)
end
local function t(text)
local x,y = term.getSize()
local x1,y1 = term.getCursorPos()
term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y1)
print(text)
end
local function w()
term.setTextColor(colors.white)
end
term.setCursorPos(0,4)
y()
t("testquestion")
w()
options1 = {"1) test1","2) test2","3) test3"}
term.setCursorPos(0,6)
for i = 1, #options1 do
t(options1[i])
end
kp(keys.two)
Edited on 13 July 2015 - 04:01 PM