134 posts
Posted 14 March 2012 - 02:15 PM
Hellow pros! ;)/>/>
i was wondering if some of you would take your time and guide me through a way to make a menu in computercraft, i've been seaching on the internet for some sort of topic that i could learn of, but didnt find any, so if any 1 would help me i would, really appreciate! :)/>/>
Regard Plazter
!!OBS!!
im completely a noob in lua B)/>/>
EDIT: a coude would be fine aswell :mellow:/>/>
What i simply is hunting for is something like
">>[Turn on Reactor]" ? B)/>/>
that small code will be fine for me to play with B)/>/> thanks! B)/>/>
14 posts
Posted 14 March 2012 - 03:35 PM
local exit = 0
local Lights = 0
local BuildCraft = 0
local PowerOn = {}
while exit == 0 do
shell.run("clear")
print(" ")
print(" **Control Panel Status**")
write(" 1. Lights - ")
if Lights == 1 then
print("On")
else
print("Off")
end
print(" ")
print(" ")
print(" ")
write(" Hit enter to continue... ")
Check = read()
shell.run("clear")
print(" ")
print(" **Control Panel Operations**")
write(" 1. Turn Lights ")
if Lights == 1 then
print("Off")
else
print("On")
end
print(" 2. Exit")
print(" ")
print(" ")
write(" Choice: ")
input = read()
if input == "1" then
if Lights == 1 then
rs.setBundledOutput("back", colors.black)
Lights = 0
else
rs.setBundledOutput("back", colors.white)
Lights = 1
end
elseif input == "2" then
print("Ending...")
write(" Hit enter to continue... ")
Check = read()
exit = 1
else
exit = 0
end
end
Here is some minor code to get your hands dirt
It opens up a menu after displaying the current status of the Lights, just rename variables and your home free.
Edit: So with the code, you choose the option then it sets the white wire in the bundled cable attached to the back. Also if you want to just use red stone swap that
Line out for rs.setOutput("back",true). Or you could swap out any side for "back" and then set false instead of true.
Hope this helps.
454 posts
Location
London
Posted 14 March 2012 - 03:50 PM
You could take a look at this code, which I modified some time ago:
http://www.computercraft.info/forums2/index.php?/topic/398-help-improving/page__view__findpost__p__2503Tell me if you'd like me to make it more generic, I might make a tutorial for it.
134 posts
Posted 14 March 2012 - 04:11 PM
local exit = 0
local Lights = 0
local BuildCraft = 0
local PowerOn = {}
while exit == 0 do
shell.run("clear")
print(" ")
print(" **Control Panel Status**")
write(" 1. Lights - ")
if Lights == 1 then
print("On")
else
print("Off")
end
print(" ")
print(" ")
print(" ")
write(" Hit enter to continue... ")
Check = read()
shell.run("clear")
print(" ")
print(" **Control Panel Operations**")
write(" 1. Turn Lights ")
if Lights == 1 then
print("Off")
else
print("On")
end
print(" 2. Exit")
print(" ")
print(" ")
write(" Choice: ")
input = read()
if input == "1" then
if Lights == 1 then
rs.setBundledOutput("back", colors.black)
Lights = 0
else
rs.setBundledOutput("back", colors.white)
Lights = 1
end
elseif input == "2" then
print("Ending...")
write(" Hit enter to continue... ")
Check = read()
exit = 1
else
exit = 0
end
end
Here is some minor code to get your hands dirt
It opens up a menu after displaying the current status of the Lights, just rename variables and your home free.
Edit: So with the code, you choose the option then it sets the white wire in the bundled cable attached to the back. Also if you want to just use red stone swap that
Line out for rs.setOutput("back",true). Or you could swap out any side for "back" and then set false instead of true.
Hope this helps.
Not exactly what i was looking for, but looks nice mate! :mellow:/>/>
You could take a look at this code, which I modified some time ago:
http://www.computerc...ndpost__p__2503Tell me if you'd like me to make it more generic, I might make a tutorial for it.
that 1 i dont really can get to work :/ dno wher to change the outputs :/
473 posts
Location
Poland
Posted 14 March 2012 - 04:11 PM
function CUI(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("Select a number[arrow up/arrow down]")
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
How about this?
134 posts
Posted 14 March 2012 - 04:53 PM
function CUI(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("Select a number[arrow up/arrow down]")
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
How about this?
Ugm.. it dont show me that it does anything :mellow:/>/>
473 posts
Location
Poland
Posted 14 March 2012 - 04:58 PM
you have to call it with a table as a param, like
local choice=CUI({"Option1","Option2"})
and it will output the number of the chosen option.
134 posts
Posted 14 March 2012 - 05:06 PM
you have to call it with a table as a param, like
local choice=CUI({"Option1","Option2"})
and it will output the number of the chosen option.
local choice=CUI({"Option1","Option2"})up in the first part before the first "end" or in the lower 1? :mellow:/>/>
sorry for being noobish ;)/>/>
473 posts
Location
Poland
Posted 14 March 2012 - 05:09 PM
no, paste the function somewhere and call it using local choice=CUI({"Option1","Option2"})
the choice var would hold the chosen option
134 posts
Posted 14 March 2012 - 05:15 PM
function CUI(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("Select a number[arrow up/arrow down]")
local choice=CUI({"Option1","Option2"})
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
Would that work? because it really dont seems like :S or what am i doing wrong? :mellow:/>/>
473 posts
Location
Poland
Posted 14 March 2012 - 05:28 PM
use it like:
function CUI(m) --This is a FUNCTION
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("Select a number[arrow up/arrow down]")
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
--And here starts the normal code
local choice=CUI({"Option1","Option2"})
print("You've chosen "..choice)
134 posts
Posted 14 March 2012 - 05:43 PM
now if im not wrong then
for adding an function would be like:
local choice=CUI({"Option1","Option2"})
if a= rs.setOutput("left", true")
print("You've chosen "..choice)
something like that?