Posted 25 March 2013 - 03:32 PM
Hello!
A little background so that when I say things people don't get overly confused:
I started playing on a feed the beast server where we were looking for a good solution for getting around using the MYSTCraft linking books. Being the borderline MYST-Geek that I am (loved every game in the series and was sad that CYAN Worlds was hit as hard as it was), I designed a Nexus Hub machine that relies on a computer terminal to make selections.
The problem:
The code that I out together doesn't work properly. I took a menu script that I found here and added on some basic code to respond to it.
at the last three lines, the space is where the player names go, using elseif for additional names and the book() being filled by colors.color (example, colors.blue).
After fixing numerous typos in the terminal, I got the menu to come up. However, when I made a selection, it would come up with a command line. Obviously, this was because the program does not have a loop built in, so I added in a "while true do" to try to get it to bring up the menu again after a selection. Instead, it has locked the terminal in the loop and the same wire is turning on and off over and over.
The only other way I can think of to get the system to start over after execution is to somehow tie in a "reboot" since I saved the code as the startup.
What is the "best" way to resolve the issue?
A little background so that when I say things people don't get overly confused:
I started playing on a feed the beast server where we were looking for a good solution for getting around using the MYSTCraft linking books. Being the borderline MYST-Geek that I am (loved every game in the series and was sad that CYAN Worlds was hit as hard as it was), I designed a Nexus Hub machine that relies on a computer terminal to make selections.
The problem:
The code that I out together doesn't work properly. I took a menu script that I found here and added on some basic code to respond to it.
local function menu(...)
local sel = 1
local list = {...}
local offX,offY = term.getCursorPos()
local curX,curY = term.getCursorPos()
while true do
if sel > #list then sel = 1 end
if sel < 1 then sel = #list end
for i = 1,#list do
term.setCursorPos(offX,offY+i-1)
if sel == i then
print("["..list[i].."]") print(">"..list[i])
else
print(" "..list[i].." ")
end
end
while true do
local e,e1,e2,e3,e4,e5 = os.pullEvent()
if e == "key" then
if e1 == 200 then -- up key
sel = sel-1
break
end
if e1 == 208 then -- down key
sel = sel+1
break
end
if e1 == 28 then
term.setCursorPos(curX,curY)
return list[sel],sel
end
end
end
end
end
local function book(a)
local side = "back"
local color = a
redstone.setBundledOutput(side, color)
sleep(1)
redstone.setBundledOutput(side, 0)
sleep(5)
redstone.setBundledOutput(side, colors.purple)
sleep(1)
redstone.setBundledOutput(side, 0)
end
print("Please select a destination")
local selection = menu(" ")
if selection == " " then
book()
at the last three lines, the space is where the player names go, using elseif for additional names and the book() being filled by colors.color (example, colors.blue).
After fixing numerous typos in the terminal, I got the menu to come up. However, when I made a selection, it would come up with a command line. Obviously, this was because the program does not have a loop built in, so I added in a "while true do" to try to get it to bring up the menu again after a selection. Instead, it has locked the terminal in the loop and the same wire is turning on and off over and over.
The only other way I can think of to get the system to start over after execution is to somehow tie in a "reboot" since I saved the code as the startup.
What is the "best" way to resolve the issue?