10 posts
Location
Germany
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
1548 posts
Location
That dark shadow under your bed...
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
10 posts
Location
Germany
Posted 28 November 2012 - 04:09 AM
oooohhh damn thanks what would i do with out this forum :DDD
1548 posts
Location
That dark shadow under your bed...
Posted 28 November 2012 - 04:14 AM
hahaha. no problems, this is where I learned Lua too
3790 posts
Location
Lincoln, Nebraska
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.
10 posts
Location
Germany
Posted 28 November 2012 - 04:40 AM
ok thanks :D/> nice to get respons :D/>
818 posts
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
10 posts
Location
Germany
Posted 28 November 2012 - 04:49 AM
Also thank i read
Cranium post not right so i miss understanded it