Posted 05 February 2014 - 10:00 AM
well i am trying to make a select menu and at the same time it listens for Messages that are equal to Online? then it has to send back some data….
but the listener doesnt work anyone know why ?? i already have seen something with parralell and stuff but i want it so you can just select stuff and Select some options on the menu. anyone can explain it to me and post the code that is correct
– Rocknet Os is created by Ramon Robben.
local termWidth, termHeight = term.getSize()
local selectedItem = 1
local onMainMenu = true
term.clear()
term.setCursorPos(1,1)
print("|————————————————|")
print("|————RockNet Internet Systems————|")
print("|———-Rocket Net Security Systems———–|")
print("|———————–||———————–|")
sleep(3)
term.clear()
term.setCursorPos(1,1)
io.write("RockNet")
function listen()
while true do
id, msg, distance = rednet.receive()
FUNCTION_THAT_RUNS_STUFF(id, msg, distance)
sleep(1)
ipv4 = os.getComputerID()
if msg = "Online?" then
sleep(1)
rednet.send(id, ipv4.." Is online!")
end
end
function Choice1()
term.clear()
term.setCursorPos(1,1)
print("Who`s Online")
sleep(1)
shell.run("WhosOnline")
end
function Choice2()
term.clear()
term.setCursorPos(1,1)
print("Send Mail")
sleep(1)
shell.run("SendMail")
end
function Choice3()
term.clear()
term.setCursorPos(1,1)
print("Read Mail")
sleep(1)
shell.run("ReadMail")
end
function Exit()
onMainMenu = false
end
mainMenu = {
[1] = { text = "Who`s Online", handler = Choice1 },
[2] = { text = "Send Mail", handler = Choice2 },
[3] = { text = "ReadMail", handler = Choice3 },
[4] = { text = "Exit", handler = Exit }
}
function printMenu( menu )
for i=1,#menu do
if i == selectedItem then
print(">> "..menu.text)
else
print(" "..menu.text)
end
end
end
function onKeyPressed( key, menu )
if key == keys.enter then
onItemSelected(menu)
elseif key == keys.up then
if selectedItem > 1 then
selectedItem = selectedItem - 1
end
elseif key == keys.down then
if selectedItem < #menu then
selectedItem = selectedItem + 1
end
end
end
function onItemSelected( menu )
menu[selectedItem].handler()
end
function main()
while onMainMenu do
term.clear()
term.setCursorPos(1,1)
printMenu(mainMenu)
event, key = os.pullEvent("key")
onKeyPressed(key,mainMenu)
end
end
listen()
main()
Any help is much apreciated
i think i made serveral mistakes with the Listen Code…