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

Need help making Menu

Started by joshf67, 30 August 2012 - 09:37 PM
joshf67 #1
Posted 30 August 2012 - 11:37 PM
I need help making a menu, for some reason i go through to a certain part and then the program just ends…
here is the code if you could help me out that would be cool.

please ignore how stupid the menu looks it doesn't copy correctly when i copy and paste it.

if it really bugs you here is the pastebin link:

http://pastebin.com/bcFs8x6Z


otherwise here is the code


start = 1
if start == 1 then
local input1 = 0
local input2 = 0
local input3 = 0
print("Enter bot's coords")
print(" ")
io.write("X: ")
x1 = io.read()
if x1 == 0 then
input1 = 0
else
input1 = x1 + input1
end
print(" ")
io.write("Y: ")
y1 = io.read()
if y1 == 0 then
input2 = 0
else
input2 = y1 + input2
end
print(" ")
io.write("Z: ")
z1 = io.read()
if z1 == 0 then
input3 = 0
else
input3 = z1 + input3
end
term.clear()
term.setCursorPos( 1, 1 )
print("Your Bot's location is:")
io.write(" X: "..input1)
io.write("   Y: "..input2)
io.write("   Z: "..input3)
print(" ")
print("Make sure these are right")
print("if they are not press ctrl+t")
sleep(10)
term.clear()
term.setCursorPos( 1, 1 )
  print("Good, Now what do you want to do?")
  term.clear()
  term.setCursorPos( 1, 1 )
  print("")
  print("---------------------------------")
  print("	   Orbital Strike Mode   (1) ")
  print("---------------------------------")
  print("		   Mining Mode	   (2) ")
  print("---------------------------------")
  print("	    Transporting Mode    (3) ")
  print("---------------------------------")
  print("")
  print("")
  sleep(1)
  c1 = io.read
 
  if c1 == 1 then
  print("")
  print("----------------------------------------------------")
  print(" **   *   *	 *	   *  * *  * * ___________ *   ")
  print("    **  *   *    *  * *   * *  * * |___________|   *")
  print("  Orbital Strike Mode   * *  *    *|		   | *  ")
  print(" *  *   *	 *   *    *  * *   *  |    TNT    |   *")
  print("   * *Have Fun!   *  *   * *	 * |___________|*   ")
  print("  *	 *  *    *	  * *    *   *|___________|  * ")
  print("----------------------------------------------------")
  sleep(10)
  term.clear()
  erm.setCursorPos( 1, 1 )
  end
 
 
 
 
 
Exerro #2
Posted 31 August 2012 - 01:57 AM
ok i have the fixed code for you here:
Spoiler

start = 1
if start == 1 then
local input1 = 0
local input2 = 0
local input3 = 0
print("Enter bot's coords")
print(" ")
io.write("X: ")
x1 = io.read()
if x1 == 0 then
  input1 = 0
else
  input1 = x1 + input1
end
print(" ")
io.write("Y: ")
y1 = io.read()
if y1 == 0 then
  input2 = 0
else
  input2 = y1 + input2
end
print(" ")
io.write("Z: ")
z1 = io.read()
if z1 == 0 then
  input3 = 0
else
  input3 = z1 + input3
end
term.clear()
term.setCursorPos( 1, 1 )
print("Your Bot's location is:")
io.write(" X: "..input1)
io.write("   Y: "..input2)
io.write("   Z: "..input3)
print(" ")
print("Make sure these are right")
print("if they are not press ctrl+t")
sleep(10)
term.clear()
term.setCursorPos( 1, 1 )
print("Good, Now what do you want to do?")
term.clear()
term.setCursorPos( 1, 1 )
print("")
print("---------------------------------")
print("	   Orbital Strike Mode   (1) ")
print("---------------------------------")
print("		   Mining Mode	   (2) ")
print("---------------------------------")
print("		Transporting Mode	(3) ")
print("---------------------------------")
print("")
print("")
sleep(1)
c1 = io.read() -- added () to end of read function
if c1 == "1" then -- put quotes around the 1
  print("")
  print("----------------------------------------------------")
  print(" **   *   *	 *	   *  * *  * * ___________ *   ")
  print("	**  *   *	*  * *   * *  * * |___________|   *")
  print("  Orbital Strike Mode   * *  *	*|		   | *  ")
  print(" *  *   *	 *   *	*  * *   *  |	TNT	|   *")
  print("   * *Have Fun!   *  *   * *	 * |___________|*   ")
  print("  *	 *  *	*	  * *	*   *|___________|  * ")
  print("----------------------------------------------------")
  sleep(10)
  term.clear()
  term.setCursorPos( 1, 1 ) -- was erm.setCursorPos changed to term.setCursorPos
end
end -- added an end
and an improved code here:
Spoiler

function writePos(x,y,text)
term.setCursorPos(x,y)
term.write(text)
end
function clear(x,y)
term.clear()
if x == nil or y == nil then
  term.setCursorPos(1,1)
else
  term.setCursorPos(x,y)
end
end
local start = 1
local input1 = 0
local input2 = 0
local input3 = 0
local cursorPos = 1
local tCoords  = {
0;
0;
0
} -- you can change these default values to what you want
if start == 1 then
while true do
  clear()
  writePos(1,18,tCoords[1].." "..tCoords[2].." "..tCoords[3])
  writePos(1,1,"Enter bot's coords")
  writePos(2,3,"X:")
  writePos(2,4,"Y:")
  writePos(2,5,"Z:")
  writePos(2,6,"Done")
  writePos(1,2+cursorPos,">")
  for i = 1,#tCoords do
   writePos(5,2+i,tCoords[i])
  end
  event, key = os.pullEvent()
  if key == 200 and cursorPos > 1 then
   cursorPos = cursorPos-1
  elseif key == 208 and cursorPos < 4 then
   cursorPos = cursorPos+1
  elseif key == 28 then
   if cursorPos == 1 then
	term.setCursorPos(5,3)
	local input = read()
	if input == "0" then
	 tCoords[1] = 0
	else
	 tCoords[1] = tonumber(input)+tCoords[1]
	end
   elseif cursorPos == 2 then
	term.setCursorPos(5,4)
	local input = read()
	if input == "0" then
	 tCoords[2] = 0
	else
	 tCoords[2] = tonumber(input)+tCoords[2]
	end
   elseif cursorPos == 3 then
	term.setCursorPos(5,5)
	local input = read()
	if input == "0" then
	 tCoords[3] = 0
	else
	 tCoords[3] = tonumber(input)+tCoords[3]
	end
   elseif cursorPos == 4 then
	input1 = tCoords[1]
	input2 = tCoords[2]
	input3 = tCoords[3]
	break
   end
  end
end
writePos(1,17,"Make sure these coordinates are right")
writePos(1,18,"if they are not press backspace")
event, key = os.pullEvent()
if key == 14 then
  os.reboot()
else
end
clear(1,1)
print("Good, Now what do you want to do?")
sleep(2)
clear(1,1)
writePos(1,2,"---------------------------------")
writePos(1,3,"	   Orbital Strike Mode   (1) ")
writePos(1,4,"---------------------------------")
writePos(1,5,"		   Mining Mode	   (2) ")
writePos(1,6,"---------------------------------")
writePos(1,7,"		Transporting Mode	(3) ")
writePos(1,8,"---------------------------------")
writePos(1,9,"Option: ")
c1 = io.read()
if c1 == "1" then
  print("")
  print("----------------------------------------------------")
  print(" **   *   *	 *	   *  * *  * * ___________ *   ")
  print("	**  *   *	*  * *   * *  * * |___________|   *")
  print("  Orbital Strike Mode   * *  *	*|		   | *  ")
  print(" *  *   *	 *   *	*  * *   *  |	TNT	|   *")
  print("   * *Have Fun!   *  *   * *	 * |___________|*   ")
  print("  *	 *  *	*	  * *	*   *|___________|  * ")
  print("----------------------------------------------------")
  sleep(10)
  term.clear()
  term.setCursorPos( 1, 1 )
end
end
joshf67 #3
Posted 31 August 2012 - 11:06 AM
Thank you very much

I don't understand the improved version but thanks