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

Menu Issue

Started by jtdavis99, 19 March 2012 - 06:39 PM
jtdavis99 #1
Posted 19 March 2012 - 07:39 PM
So, I'm having immense trouble with this menu system. Pretty simple and easy to understand, yet it will skip different things when you hit the left or right arrow key. So, for instance, if you hit < when it was on the + of * / + -, it would take you to * instead of / like it should. Any help?
local n=1
while true do
local x, y=term.getCursorPos()
term.clearLine()
if n == 1 then
  write(">*<   /   +   -")
elseif n == 2 then
  write ("*   >/<   +   -")

elseif n == 3 then
  write ("*   /   >+<   -")
 
elseif n == 4 then
  write ("*   /   +   >-<")

end
term.setCursorPos(x, y)
a, b=os.pullEvent()
while a~="key" do a, b=os.pullEvent()
end

if b == 203 and n == 4 then
  n = 3
end
if b == 203 and n == 3 then
  n = 2
end

if b == 203 and n == 2 then
  n = 1
end
if b == 205 and n == 1 then
  n = 2
end
if b == 205 and n == 3 then
  n = 4
end

if b == 205 and n == 2 then
  n = 3
end

if b == 28 then
  print("") break
end
end
jtdavis99 #2
Posted 19 March 2012 - 08:16 PM
No one? D;
Liraal #3
Posted 19 March 2012 - 08:17 PM
yeah now i get it, you need to write it like

if b==203 and n==4 then
n=3
else
if b==203 and n==3 then
n=2
else
--and so on
--and you need to close all the 'if's here
end
end
--etc.

basically, what happened was that it triggered the first 'if' and then triggered all the next ones. You need to use an elseif chain ass shown above

btw, i was writing this when you wrote 'no one' :D/>/>
jtdavis99 #4
Posted 19 March 2012 - 08:23 PM
yeah now i get it, you need to write it like

if b==203 and n==4 then
n=3
else
if b==203 and n==3 then
n=2
else
--and so on
--and you need to close all the 'if's here
end
end
--etc.

basically, what happened was that it triggered the first 'if' and then triggered all the next ones. You need to use an elseif chain ass shown above

btw, i was writing this when you wrote 'no one' :D/>/>

Hehe, thanks :)/>/>