Posted 21 July 2013 - 07:08 AM
hello. i have been trying to figure out how to read a printed returned value from a menu table.
every time i run the program it prints the number of the option you had selected then stops
once stopped if you retype the number it printed and hit enter then it does what its ment to do.
how do i make it so yuo dont have to retype the already printed number?
here is the code
every time i run the program it prints the number of the option you had selected then stops
once stopped if you retype the number it printed and hit enter then it does what its ment to do.
how do i make it so yuo dont have to retype the already printed number?
here is the code
function CUI(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("Select a number[arrow up/arrow down]")
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
local options={
"The Dunes",
"The trench",
"East Woods"
}
local n = CUI(options)
print(n)
track = read() - i believe this is the problem but dont know how to fix it as it needs to read the printed (n)
if track == "1" then
redstone.setOutput ("right", true)
sleep(1)
redstone.setOutput ("right", false)
print ("The dunes have been selected")
sleep(3)
print ("you may now launch when ready")
sleep(5)
os.reboot()
elseif track == "2" then
redstone.setOutput ("back", true)
sleep(1)
redstone.setOutput ("back", false)
print ("The Trench has been selected")
sleep(3)
print ("you may now launch when ready")
sleep(5)
os.reboot()
elseif track == "3" then
redstone.setOutput ("left", true)
sleep(1)
redstone.setOutput ("left", false)
print ("East Woods have been selected")
sleep(3)
print ("you may now launch when ready")
sleep(5)
os.reboot()
end