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

I Have A Menu Bug Here.

Started by mrdawgza, 24 September 2013 - 10:55 AM
mrdawgza #1
Posted 24 September 2013 - 12:55 PM
Hello, I have got a little problem on my code.
I am currently making an operating system for the regular old computers, since I just don't like the new ones.
I have a problem in my menu code;


My code:

print("1. Programs")
print("2. Shutdown")

write("Selection: ")

input = read()
if input == one then
shell.run("programs")
end

if input == 2 then
os.shutdown()

else
print("Invalid selection!")
sleep(1)
os.reboot()
end

It's a menu code, or it's supposed to be. I remember when I played Tekkit I made a menu code of some sorts, and tried to make it here.
Note, the code does look a little bit empty because I have tried making an operating system before and I would get this problem,
so I just did a little menu (or whatever it is) on what I remembered to see if it was just a bug.

The problem:
Normally, on a old menu, you'd be asked what selection you wish to use, like, Shutdown and Programs.
So here I have those two, but when you put in 1 or 2, it says Invalid Selection!
When it should normally do the action.
Sorry if it's a stupid mistake I did on my side, I'm a noob at coding :P/>


I did try and remake my menu from Tekkit, but I don't think it's successful.

If you can fix it, I will probably put credit to helping me on my operating system.
Zudo #2
Posted 24 September 2013 - 12:59 PM
Read() always returns a string, so:

print("1. Programs")
print("2. Shutdown")

write("Selection: ")

input = read()
if input == "1" then
shell.run("programs")
end

if input == "2" then
os.shutdown()

else
print("Invalid selection!")
sleep(1)
os.reboot()
end

would work
mrdawgza #3
Posted 24 September 2013 - 01:10 PM
Read() always returns a string, so:

print("1. Programs")
print("2. Shutdown")

write("Selection: ")

input = read()
if input == "1" then
shell.run("programs")
end

if input == "2" then
os.shutdown()

else
print("Invalid selection!")
sleep(1)
os.reboot()
end

would work

It does work, but now if I submit 1, it'll do the action and display Invalid Selection! Then return to the menu.
Any ideas? (+I'm giving you credit in the operating system ZudoHackz)
Zudo #4
Posted 24 September 2013 - 01:15 PM

print("1. Programs")
print("2. Shutdown")

write("Selection: ")

input = read()
if input == "1" then
shell.run("programs")

elseif input == "2" then
os.shutdown()

else
print("Invalid selection!")
sleep(1)
os.reboot()
end
Goof #5
Posted 24 September 2013 - 01:18 PM
heh :P/> got Ninja'd by ZudoHackz :P/>

SpoilerUse the elseif statement :P/>/>


print("1. Programs")
print("2. Shutdown")

write("Selection: ")

input = read()
if input == "1" then
	shell.run("programs")
-- Use elseif 
elseif input == "2" then 
	os.shutdown()
else
	print("Invalid selection!")
	sleep(1)
	os.reboot()
end
Cranium #6
Posted 24 September 2013 - 01:22 PM
Wait, you DON'T like colors and touchscreen support??? What is wrong with you?
mrdawgza #7
Posted 24 September 2013 - 01:25 PM
Thank you Mikk809h. Dunno what happened there ZudoHackz :P/> …
Anyway I'll credit both of you in my operating system.

Wait, you DON'T like colors and touchscreen support??? What is wrong with you?
Nah, I've just messed around and spent too much time on the old computers. It's like getting the regular granny to use a Samsung Galaxy S4.

–Edit
Nah, I've just messed around and spent too much time on the old computers. It's like getting the regular granny to use a Samsung Galaxy S4.
And I prefer the old computers.