Jump to content




I Have A Menu Bug Here.


  • You cannot reply to this topic
6 replies to this topic

#1 mrdawgza

  • Members
  • 110 posts
  • LocationSouth Africa

Posted 24 September 2013 - 11:55 AM

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.

#2 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 24 September 2013 - 11:59 AM

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

#3 mrdawgza

  • Members
  • 110 posts
  • LocationSouth Africa

Posted 24 September 2013 - 12:10 PM

View PostZudoHackz, on 24 September 2013 - 11:59 AM, said:

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)

#4 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 24 September 2013 - 12: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


#5 Goof

  • Members
  • 751 posts

Posted 24 September 2013 - 12:18 PM

heh :P got Ninja'd by ZudoHackz :P

Spoiler


#6 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 24 September 2013 - 12:22 PM

Wait, you DON'T like colors and touchscreen support??? What is wrong with you?

#7 mrdawgza

  • Members
  • 110 posts
  • LocationSouth Africa

Posted 24 September 2013 - 12:25 PM

Thank you Mikk809h. Dunno what happened there ZudoHackz :P ...
Anyway I'll credit both of you in my operating system.

View PostCranium, on 24 September 2013 - 12:22 PM, said:

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.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users