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

The Menu dont accept the key 28

Started by Radioaktiv3, 28 November 2012 - 02:21 AM
Radioaktiv3 #1
Posted 28 November 2012 - 03:21 AM
Hi my menu is close to be finished , the only thing that dont work ist the key 28 ! Why?


selected = 1
maxEintrag = 3
selectedsymbol = ">>"
reboot = false
pressedOk = 0
term.clear()
local menuEintrage = {"a","b","Exit","d","e"}
function draw()

x = 1
term.clear()
term.setCursorPos(1,1)
while x < maxEintrag + 1 do
if selected == x then
term.setCursorPos(1,x)
print(string.format("%s%s",selectedsymbol,menuEintrage[x]))
else
term.setCursorPos(3,x)
print(menuEintrage[x])
end
x = x + 1
end
end
draw()
function click()
if selected == 1 then
 
end
if slected == 2 then
  print("test")
end
if slected == 3 then
  os.reboot()
end
end
repeat
none, key = os.pullEvent ("key")
if key == 208 then
selected = selected + 1
if selected > maxEintrag then
selected = 1
end
draw()
end
if key == 200 then
selected = selected-1
if selected <= 0 then
selected = maxEintrag
end
draw()
end
if key == 28 then
click()
end
until reboot == true

Thanks for your help ;D

Sry for my bad English its not my native languche
KaoS #2
Posted 28 November 2012 - 04:07 AM
well you have spelled selected incorrectly for selection 2 and 3 in the click() function, that may cause it not to select correctly
Radioaktiv3 #3
Posted 28 November 2012 - 04:09 AM
oooohhh damn thanks what would i do with out this forum :DDD
KaoS #4
Posted 28 November 2012 - 04:14 AM
hahaha. no problems, this is where I learned Lua too
Cranium #5
Posted 28 November 2012 - 04:36 AM
To clean up your code a bit, you could do with a few elseif's It's far better than writing an if statement for each condition you want to check.
Radioaktiv3 #6
Posted 28 November 2012 - 04:40 AM
ok thanks :D/> nice to get respons :D/>
Doyle3694 #7
Posted 28 November 2012 - 04:44 AM
if a == 1 then
   -- stuffs
elseif a == 2 then
   --more stuffs
elseif a == 3 then
   --even more stuffs
else
   --Derpaderp
end
Radioaktiv3 #8
Posted 28 November 2012 - 04:49 AM
Also thank i read
Cranium
post not right so i miss understanded it