Posted 23 September 2012 - 10:33 AM
ok so i have this menu set out. <– thanks to craniumkid for helping me code it.
anyway i have a problem. everytime i hit enter over a option on the menu it goes to the top of the menu and executes the right code. my problem is that i dont want it to go to the top. i want to hit enter over an option, then it executes the code AND it stays on the option i chose. heres my code :
anyway i have a problem. everytime i hit enter over a option on the menu it goes to the top of the menu and executes the right code. my problem is that i dont want it to go to the top. i want to hit enter over an option, then it executes the code AND it stays on the option i chose. heres my code :
options = {
"Drop Payload",
"Go Up",
"Go Down",
"Go Left",
"Go Right",
"Go Forward",
"Go Backward",
}
local function opt(m,mY)
n=1
l=#m
while true do
for i=1, l, 1 do
if i==n then
local x, y = term.getSize()
local b = string.len(">"..m[i].."<")/2
local x = (x/2)-b
term.setCursorPos(x,i+mY)
term.clearLine()
print(">"..m[i].."<")
else
local x, y = term.getSize()
b = string.len(m[i])/2
x = (x/2)-b
term.setCursorPos(x,i+mY)
term.clearLine()
print(m[i]) end
end
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
while true do
term.clear()
rednet.open("top")
local input = opt(options,0)
if input == 1 then
rednet.send(id,"payload,1")
elseif input == 2 then
rednet.send(id,"up,1")
elseif input == 3 then
rednet.send(id,"down,1")
end
end
all help would be appreciated. thanks -Cheeky