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

Menu

Started by Tekkitown, 10 July 2012 - 09:19 PM
Tekkitown #1
Posted 10 July 2012 - 11:19 PM
Hello,
I got a new project to script a menu on my computer

I have a image how it looks atm


Thats my startup but its wrong

the menu must be:

Maak een keuze:

[ Lampen 2Bizzzy ]
Lampen Arjen
Deur

Sorry its dutch:

translate:
lampen = lights
deur = door

when I go to a Light system then it looks like this



Translate:

Aan = Lights on
uit = Lights off
terug = back to main menu ( that meens os.reboot() )

but it has to looks like this

Lampen

[ Aan ]
Uit
Terug

this is the working script what i have right now but whit the wrong menu

Spoilerlocal w,h = term.getSize()
function printCentred( y, s )
local x = math.floor((w - string.len(s)) / 2)
term.setCursorPos(x,y)
term.clearLine()
term.write( s )
end
local nOption = 1
– Display menu
local function drawMenu()
term.clear()
term.setCursorPos(1,1)
term.write( "2Bizzzy's System" )
term.setCursorPos(w-11,1)
if nOption == 1 then
term.write( "Keuze 1" )
elseif nOption == 2 then
term.write( "Keuze 2" )
else
term.write( "Keuze 3" )
end

end
– Display the frontend
term.clear()
local function drawFrontend()
printCentred( math.floor(h/2) - 3, "" )
printCentred( math.floor(h/2) - 2, "Maak een keuze" )
printCentred( math.floor(h/2) - 1, "" )
printCentred( math.floor(h/2) + 0, ((nOption == 1) and "[ Lampen 1 ]") or "Lampen 1" )
printCentred( math.floor(h/2) + 1, ((nOption == 2) and "[ Deur 2 ]") or "Deur 2" )
printCentred( math.floor(h/2) + 2, ((nOption == 3) and "[ … 3 ]") or "… 3" )
printCentred( math.floor(h/2) + 3, "" )
end
– Call functions for display menu
drawMenu()
drawFrontend()
while true do
local e,p = os.pullEvent()
if e == "key" then
local key = p
if key == 17 or key == 200 then
– Up
if nOption > 1 then
nOption = nOption - 1
drawMenu()
drawFrontend()
end
elseif key == 31 or key == 208 then
– Down
if nOption < 3 then – Change 3 by the number of option.
nOption = nOption + 1
drawMenu()
drawFrontend()
end
elseif key == 28 then
– Enter
break
end
end
end
term.clear()
– Conditions
if nOption == 1 then
local w,h = term.getSize()
function printCentred( y, s )
local x = math.floor((w - string.len(s)) / 2)
term.setCursorPos(x,y)
term.clearLine()
term.write( s )
end
local nOption = 1
– Display menu
local function drawMenu()
term.clear()
term.setCursorPos(1,1)
term.write( "2Bizzzy's Light System" )
term.setCursorPos(w-11,1)
if nOption == 1 then
term.write( "Keuze 1" )
elseif nOption == 2 then
term.write( "Keuze 2" )

end

end
– Display the frontend
term.clear()
local function drawFrontend()
printCentred( math.floor(h/2) - 3, "" )
printCentred( math.floor(h/2) - 2, "Lampen" )
printCentred( math.floor(h/2) - 1, "" )
printCentred( math.floor(h/2) + 0, ((nOption == 1) and "[ Aan ]") or "Aan" )
printCentred( math.floor(h/2) + 1, ((nOption == 2) and "[ Uit ]") or "Uit" )

printCentred( math.floor(h/2) + 3, "" )
end

– Call functions for display menu
drawMenu()
drawFrontend()
while true do
local e,p = os.pullEvent()
if e == "key" then
local key = p
if key == 17 or key == 200 then
– Up
if nOption > 1 then
nOption = nOption - 1
drawMenu()
drawFrontend()
end
elseif key == 31 or key == 208 then
– Down
if nOption < 3 then – Change 3 by the number of option.
nOption = nOption + 1
drawMenu()
drawFrontend()
end
elseif key == 28 then
– Enter
break
end
end
end
term.clear()
– Conditions
if nOption == 1 then
local side = "left"
local password = "sjoerd"
local opentime = "1"
term.clear()
term.setCursorPos(1,1)
write("Wachtwoord: ")
local input = read()
if input == password then
term.clear()
term.setCursorPos(1,1)
print("Wachtwoord Correct!")
rs.setBundledOutput(side, colors.green)
sleep(opentime)
os.reboot()
else
term.clear()
term.setCursorPos(1,1)
Print("Wachtwoord Incorrect! Griefer?")
sleep(2)
os.reboot()
end
elseif nOption == 2 then
local side = "left"
local password = "sjoerd"
local opentime = "1"
term.clear()
term.setCursorPos(1,1)
write("Wachtwoord: ")
local input = read()
if input == password then
term.clear()
term.setCursorPos(1,1)
print("Wachtwoord Correct!")
rs.setBundledOutput(side, colors.red)
sleep(opentime)
os.reboot()
else
term.clear()
term.setCursorPos(1,1)
Print("Wachtwoord Incorrect! Griefer?")
sleep(2)
os.reboot()
end
end
elseif nOption == 2 then
local w,h = term.getSize()
function printCentred( y, s )
local x = math.floor((w - string.len(s)) / 2)
term.setCursorPos(x,y)
term.clearLine()
term.write( s )
end
local nOption = 1
– Display menu
local function drawMenu()
term.clear()
term.setCursorPos(1,1)
term.write( "2Bizzzy's Door System" )
term.setCursorPos(w-11,1)
if nOption == 1 then
term.write( "Keuze 1" )
elseif nOption == 2 then
term.write( "Keuze 2" )

end

end
– Display the frontend
term.clear()
local function drawFrontend()
printCentred( math.floor(h/2) - 3, "" )
printCentred( math.floor(h/2) - 2, "Deur" )
printCentred( math.floor(h/2) - 1, "" )
printCentred( math.floor(h/2) + 0, ((nOption == 1) and "[ Openen ]") or "Openen " )
printCentred( math.floor(h/2) + 1, ((nOption == 2) and "[ Sluiten ]") or "Sluiten" )

printCentred( math.floor(h/2) + 3, "" )
end
– Call functions for display menu
drawMenu()
drawFrontend()
while true do
local e,p = os.pullEvent()
if e == "key" then
local key = p
if key == 17 or key == 200 then
– Up
if nOption > 1 then
nOption = nOption - 1
drawMenu()
drawFrontend()
end
elseif key == 31 or key == 208 then
– Down
if nOption < 3 then – Change 3 by the number of option.
nOption = nOption + 1
drawMenu()
drawFrontend()
end
elseif key == 28 then
– Enter
break
end
end
end
term.clear()
– Conditions
if nOption == 1 then
local side = "right"
local password = "sjoerd"
local opentime = "10"
term.clear()
term.setCursorPos(1,1)
write("Wachtwoord: ")
local input = read()
if input == password then
term.clear()
term.setCursorPos(1,1)
print("Wachtwoord Correct!")
rs.setBundledOutput(side, colors.green)
sleep(opentime)
rs.setBundledOutput(side, colors.red)
os.reboot()
else
term.clear()
term.setCursorPos(1,1)
Print("Wachtwoord Incorrect! Griefer?")
sleep(2)
os.reboot()
end
elseif nOption == 2 then
local side = "right"
local password = "sjoerd"
local opentime = "1"
term.clear()
term.setCursorPos(1,1)
write("Wachtwoord: ")
local input = read()
if input == password then
term.clear()
term.setCursorPos(1,1)
print("Wachtwoord Correct!")
rs.setBundledOutput(side, colors.red)
sleep(opentime)
os.reboot()
else
term.clear()
term.setCursorPos(1,1)
Print("Wachtwoord Incorrect! Griefer?")
sleep(2)
os.reboot()
end
end
end





I edit it to what it must be but it failed i get the error :startup:line 242 <eof> expected
i had it on my working script to the fault was a forgoten end
Here is the script with the error




Spoilerlocal w,h = term.getSize()
function printCentred( y, s )
local x = math.floor((w - string.len(s)) / 2)
term.setCursorPos(x,y)
term.clearLine()
term.write( s )
end
local nOption = 1
– Display menu
local function drawMenu()
term.clear()
term.setCursorPos(1,1)
term.write( "2Bizzzy's System" )
term.setCursorPos(w-11,1)
if nOption == 1 then
term.write( "Keuze 1" )
elseif nOption == 2 then
term.write( "Keuze 2" )
else
term.write( "Keuze 3" )
end

end
– Display the frontend
term.clear()
local function drawFrontend()
printCentred( math.floor(h/2) - 3, "" )
printCentred( math.floor(h/2) - 2, "Maak een keuze" )
printCentred( math.floor(h/2) - 1, "" )
printCentred( math.floor(h/2) + 0, ((nOption == 1) and "[ Lampen 2Bizzzy 1 ]") or "Lampen 2Bizzzy 1" )
printCentred( math.floor(h/2) + 1, ((nOption == 2) and "[ Lampen Arjen 2 ]") or "Lampen Arjen 2" )
printCentred( math.floor(h/2) + 2, ((nOption == 3) and "[ Deur 3 ]") or "Deur 3" )
printCentred( math.floor(h/2) + 3, "" )
end

– Call functions for display menu
drawMenu()
drawFrontend()
while true do
local e,p = os.pullEvent()
if e == "key" then
local key = p
if key == 17 or key == 200 then
– Up
if nOption > 1 then
nOption = nOption - 1
drawMenu()
drawFrontend()
end
elseif key == 31 or key == 208 then
– Down
if nOption < 3 then – Change 3 by the number of option.
nOption = nOption + 1
drawMenu()
drawFrontend()
end
elseif key == 28 then
– Enter
break
end
end
end
term.clear()
– Conditions


—– 2Bizzzy lampen —– 2Bizzzy lampen —– 2Bizzzy lampen
—– 2Bizzzy lampen —– 2Bizzzy lampen —– 2Bizzzy lampen
—– 2Bizzzy lampen —– 2Bizzzy lampen —– 2Bizzzy lampen
—– 2Bizzzy lampen —– 2Bizzzy lampen —– 2Bizzzy lampen

if nOption == 1 then
local w,h = term.getSize()
function printCentred( y, s )
local x = math.floor((w - string.len(s)) / 2)
term.setCursorPos(x,y)
term.clearLine()
term.write( s )
end
local nOption = 1
– Display menu
local function drawMenu()
term.clear()
term.setCursorPos(1,1)
term.write( "2Bizzzy's Light System" )
term.setCursorPos(w-11,1)
if nOption == 1 then
term.write( "Keuze 1" )
elseif nOption == 2 then
term.write( "Keuze 2" )

end

end
– Display the frontend
term.clear()
local function drawFrontend()
printCentred( math.floor(h/2) - 3, "" )
printCentred( math.floor(h/2) - 2, "Lampen 2Bizzzy" )
printCentred( math.floor(h/2) - 1, "" )
printCentred( math.floor(h/2) + 0, ((nOption == 1) and "[ Aan ]") or "Aan" )
printCentred( math.floor(h/2) + 1, ((nOption == 2) and "[ Uit ]") or "Uit" )

printCentred( math.floor(h/2) + 3, "" )
end

– Call functions for display menu
drawMenu()
drawFrontend()
while true do
local e,p = os.pullEvent()
if e == "key" then
local key = p
if key == 17 or key == 200 then
– Up
if nOption > 1 then
nOption = nOption - 1
drawMenu()
drawFrontend()
end
elseif key == 31 or key == 208 then
– Down
if nOption < 3 then – Change 3 by the number of option.
nOption = nOption + 1
drawMenu()
drawFrontend()
end
elseif key == 28 then
– Enter
break
end
end
end
term.clear()
– Conditions
if nOption == 1 then
local side = "left"
local password = "sjoerd"
local opentime = "1"
term.clear()
term.setCursorPos(1,1)
write("Wachtwoord: ")
local input = read()
if input == password then
term.clear()
term.setCursorPos(1,1)
print("Wachtwoord Correct!")
rs.setBundledOutput(side, colors.green)
sleep(opentime)

os.reboot()
else
term.clear()
term.setCursorPos(1,1)
Print("Wachtwoord Incorrect! Griefer?")
sleep(2)
os.reboot()
end
elseif nOption == 2 then
local side = "left"
local password = "sjoerd"
local opentime = "1"
term.clear()
term.setCursorPos(1,1)
write("Wachtwoord: ")
local input = read()
if input == password then
term.clear()
term.setCursorPos(1,1)
print("Wachtwoord Correct!")
rs.setBundledOutput(side, colors.red)
sleep(opentime)
os.reboot()
else
term.clear()
term.setCursorPos(1,1)
Print("Wachtwoord Incorrect! Griefer?")
sleep(2)
os.reboot()
end
end
end


—– Arjen lampen—– Arjen lampen—– Arjen lampen
—– Arjen lampen—– Arjen lampen—– Arjen lampen
—– Arjen lampen—– Arjen lampen—– Arjen lampen
—– Arjen lampen—– Arjen lampen—– Arjen lampen



elseif nOption == 2 then
local w,h = term.getSize()
function printCentred( y, s )
local x = math.floor((w - string.len(s)) / 2)
term.setCursorPos(x,y)
term.clearLine()
term.write( s )
end
local nOption = 1
– Display menu
local function drawMenu()
term.clear()
term.setCursorPos(1,1)
term.write( "Arjen's Light System" )
term.setCursorPos(w-11,1)
if nOption == 1 then
term.write( "Keuze 1" )
elseif nOption == 2 then
term.write( "Keuze 2" )
elseif nOption == 3 then
term.write( "Keuze 3" )

end

end
– Display the frontend
term.clear()
local function drawFrontend()
printCentred( math.floor(h/2) - 3, "" )
printCentred( math.floor(h/2) - 2, "Lampen Arjen" )
printCentred( math.floor(h/2) - 1, "" )
printCentred( math.floor(h/2) + 0, ((nOption == 1) and "[ Aan ]") or "Aan " )
printCentred( math.floor(h/2) + 1, ((nOption == 2) and "[ Uit ]") or "Uit " )
printCentred( math.floor(h/2) + 2, ((nOption == 3) and "[ Terug ]") or "Terug" )
printCentred( math.floor(h/2) + 3, "" )
end


– Call functions for display menu
drawMenu()
drawFrontend()

while true do
local e,p = os.pullEvent()
if e == "key" then
local key = p
if key == 17 or key == 200 then
– Up
if nOption > 1 then
nOption = nOption - 1
drawMenu()
drawFrontend()
end
elseif key == 31 or key == 208 then
– Down
if nOption < 3 then – Change 3 by the number of option.
nOption = nOption + 1
drawMenu()
drawFrontend()
end
elseif key == 28 then
– Enter
break
end
end
end
term.clear()
– Conditions
if nOption == 1 then
local side = "left"
local password = "sjoerd"
local opentime = "1"
term.clear()
term.setCursorPos(1,1)
write("Wachtwoord: ")
local input = read()
if input == password then
term.clear()
term.setCursorPos(1,1)
print("Wachtwoord Correct!")
rs.setBundledOutput(side, colors.green)
sleep(opentime)

os.reboot()
else
term.clear()
term.setCursorPos(1,1)
Print("Wachtwoord Incorrect! Griefer?")
sleep(2)
os.reboot()
end
elseif nOption == 2 then
local side = "left"
local password = "sjoerd"
local opentime = "1"
term.clear()
term.setCursorPos(1,1)
write("Wachtwoord: ")
local input = read()
if input == password then
term.clear()
term.setCursorPos(1,1)
print("Wachtwoord Correct!")
rs.setBundledOutput(side, colors.red)
sleep(opentime)
os.reboot()
else
term.clear()
term.setCursorPos(1,1)
Print("Wachtwoord Incorrect! Griefer?")
sleep(2)
os.reboot()
end

elseif nOption == 3 then
os.reboot()
end
end


—– 2Bizzzy Deur —– 2Bizzzy Deur —– 2Bizzzy Deur —– 2Bizzzy Deur
—– 2Bizzzy Deur —– 2Bizzzy Deur —– 2Bizzzy Deur —– 2Bizzzy Deur
—– 2Bizzzy Deur —– 2Bizzzy Deur —– 2Bizzzy Deur —– 2Bizzzy Deur
—– 2Bizzzy Deur —– 2Bizzzy Deur —– 2Bizzzy Deur —– 2Bizzzy Deur



elseif nOption == 3 then
local w,h = term.getSize()
function printCentred( y, s )
local x = math.floor((w - string.len(s)) / 2)
term.setCursorPos(x,y)
term.clearLine()
term.write( s )
end
local nOption = 1
– Display menu
local function drawMenu()
term.clear()
term.setCursorPos(1,1)
term.write( "2Bizzzy's Door System" )
term.setCursorPos(w-11,1)
if nOption == 1 then
term.write( "Keuze 1" )
elseif nOption == 2 then
term.write( "Keuze 2" )

end

end
– Display the frontend
term.clear()
local function drawFrontend()
printCentred( math.floor(h/2) - 3, "" )
printCentred( math.floor(h/2) - 2, "Deur" )
printCentred( math.floor(h/2) - 1, "" )
printCentred( math.floor(h/2) + 0, ((nOption == 1) and "[ Openen ]") or "Openen " )
printCentred( math.floor(h/2) + 1, ((nOption == 2) and "[ Sluiten ]") or "Sluiten" )

printCentred( math.floor(h/2) + 3, "" )
end


– Call functions for display menu
drawMenu()
drawFrontend()

while true do
local e,p = os.pullEvent()
if e == "key" then
local key = p
if key == 17 or key == 200 then
– Up
if nOption > 1 then
nOption = nOption - 1
drawMenu()
drawFrontend()
end
elseif key == 31 or key == 208 then
– Down
if nOption < 3 then – Change 3 by the number of option.
nOption = nOption + 1
drawMenu()
drawFrontend()
end
elseif key == 28 then
– Enter
break
end
end
end
term.clear()
– Conditions
if nOption == 1 then
local side = "right"
local password = "sjoerd"
local opentime = "10"
term.clear()
term.setCursorPos(1,1)
write("Wachtwoord: ")
local input = read()
if input == password then
term.clear()
term.setCursorPos(1,1)
print("Wachtwoord Correct!")
rs.setBundledOutput(side, colors.green)
sleep(opentime)
rs.setBundledOutput(side, colors.red)
os.reboot()
else
term.clear()
term.setCursorPos(1,1)
Print("Wachtwoord Incorrect! Griefer?")
sleep(2)
os.reboot()
end
elseif nOption == 2 then
local side = "right"
local password = "sjoerd"
local opentime = "1"
term.clear()
term.setCursorPos(1,1)
write("Wachtwoord: ")
local input = read()
if input == password then
term.clear()
term.setCursorPos(1,1)
print("Wachtwoord Correct!")
rs.setBundledOutput(side, colors.red)
sleep(opentime)
os.reboot()
else
term.clear()
term.setCursorPos(1,1)
Print("Wachtwoord Incorrect! Griefer?")
sleep(2)
os.reboot()
end
end
end


Maybe if your dutch and you dont understand my topic :)/>/> you can add me on skype : keltjens1995 and vist me on my own Tekkit 3.0.3 server!


I hope you can help me
xuma202 #2
Posted 10 July 2012 - 11:28 PM
Try formatting your code like so:


local w,h = term.getSize()
function printCentred( y, s )
  local x = math.floor((w - string.len(s)) / 2)
  term.setCursorPos(x,y)
  term.clearLine()
  term.write( s )
end
local nOption = 1
-- Display menu
local function drawMenu()
  term.clear()
  term.setCursorPos(1,1)
  term.write( "2Bizzzy's System" )
  term.setCursorPos(w-11,1)
  if nOption == 1 then
	term.write( "Keuze 1" )
  elseif nOption == 2 then
	term.write( "Keuze 2" )
  else
	term.write( "Keuze 3" )
  end
end
-- Display the frontend
term.clear()
local function drawFrontend()
  printCentred( math.floor(h/2) - 3, "" )
  printCentred( math.floor(h/2) - 2, "Maak een keuze" )
  printCentred( math.floor(h/2) - 1, "" )
  printCentred( math.floor(h/2) + 0, ((nOption == 1) and "[ Lampen  2Bizzzy 1 ]") or "Lampen 2Bizzzy 1" )
  printCentred( math.floor(h/2) + 1, ((nOption == 2) and "[ Lampen   Arjen 2 ]") or "Lampen Arjen 2" )
  printCentred( math.floor(h/2) + 2, ((nOption == 3) and "[ Deur 3 ]  ") or "Deur 3" )
  printCentred( math.floor(h/2) + 3, "" )
end
-- Call functions for display menu
drawMenu()
drawFrontend()
while true do
  local e,p = os.pullEvent()
  if e == "key" then
	local key = p
	if key == 17 or key == 200 then
-- Up
	  if nOption > 1 then
		nOption = nOption - 1
		drawMenu()
		drawFrontend()
	  end
	  elseif key == 31 or key == 208 then

… It seems like you're missing some ends or they are placed wrong

PS: I'm german so I can guess what Aan, Uit and Deur means. ;-D
Tekkitown #3
Posted 10 July 2012 - 11:50 PM
How do you mean ? do i have to copy our code and paste it in my startup ?
its not the full script ;o ?

I know im missing some ends :)/>/> but i cant find where ( i dont know how Xd some time it needs 1 sometime 2 and some time 3 ends o.o )
Tekkitown #4
Posted 11 July 2012 - 10:37 AM
hmm some one :)/>/> ?

add me on skype: keltjens 1995
or vist me at my tekkit server

need some help B)/>/>
Tekkitown #5
Posted 11 July 2012 - 05:28 PM
nvm got it :)/>/> just edit my idea