Posted 27 February 2012 - 08:37 PM
At the title says.
I'm not sure if I did everything correctly, as it is the first time I've ever coded using lua(I know java well).
This is my code:
I'd really like some help.
1) I don't know exactly what file extension to use, do I use .lua?
2) Where do I put my file?
3) Did I make any major mistakes?
I'm not sure if I did everything correctly, as it is the first time I've ever coded using lua(I know java well).
This is my code:
Spoiler
availablerooms = {r1=nil,r2=nil,r3=nil,r4=nil,r5=nil,r6=nil,r7=nil,8=nil,9=nil,r10=nil,r11=nil,r12=nil}
term.clear()
textutils.slowPrint( "Welcome to the hotel booking network! Please enter the password." )
hotelpassword()
function hotelpassword()
t = io.read()
if t == "password" then
doyouwanttobook()
else
print( "That password is incorrect. Try again." )
hotelpassword()
end
end
function doyouwanttobook()
term.clear()
print("Welcome!")
print("Would you like to book a room? (Y/N)")
bookinganswer = io.read()
if bookinganswer == "Y" then
bookroom()
else
print("Would you like to list currently available rooms? (Y/N)")
listinganswer = io.read()
if listinganswer == "Y" then
listavailable()
else
print("Returning to main menu...")
sleep(3)
term.clear()
textutils.slowPrint( "Welcome to the hotel network! Please enter the password." )
hotelpassword()
end
end
end
function bookroom()
term.clear()
print("Welcome to room booking!")
print("Enter the room number(Put 'r' before the number(e.g. r1). Rooms 6-11 are large. Penthouse is r12): ")
wantedroom = io.read()
if availablerooms[wantedroom]==nil then
availablerooms[wantedroom]=b
sleep(2)
print("Room has been booked! There are " + # bookedrooms + " booked rooms")
else
print("That room isn't available, please pick another room.")
bookroom()
end
end
function listavailable()
print("Number of available rooms: " + # availablerooms ".")
end
I'd really like some help.
1) I don't know exactly what file extension to use, do I use .lua?
2) Where do I put my file?
3) Did I make any major mistakes?