17 posts
Posted 02 February 2013 - 02:10 PM
Title: [Help] Meat Delivery System, keeps printing wrong thing
Post: Hia, I have been writing a program on my Tekkit Lite world which basicly delievers you some meat. Simple. But one bit seems to keep tripping up.
inp = io.read()
while read == "fish" or read == "porkchop" or read == "steak" do
write (read)
write " is not available to order"
sleep (30)
os.reboot()
end
This is just part of it, what the problem is, it always says the order has been placed even if it wasnt supposed to. I've had a look at it for a while and can't figure out the issue, but then I am a newbie to lua
1688 posts
Location
'MURICA
Posted 02 February 2013 - 02:47 PM
You're comparing the function "read" instead of your "inp" variable, which is actually storing what the user typed. Also, the script states that the item is not available if it's in the list, and it'll do it forever with this list. You should use an if instead of a while. The script should look something like this:
inp = io.read()
if not (inp == "fish" or inp == "porkchop" or inp == "steak") then
write (inp)
write " is not available to order\n" -- added the \n here so that it makes a new line
sleep (30)
os.reboot()
end
Also, a nice tip, you can use a table to find if your input is available to order, instead of a list of if statements.
local items = {
fish = true,
porkchop = true,
steak = true
}
inp = io.read()
if not items[inp] then
write (inp)
write " is not available to order\n"
sleep (30)
os.reboot()
end
17 posts
Posted 03 February 2013 - 12:12 AM
You're comparing the function "read" instead of your "inp" variable, which is actually storing what the user typed. Also, the script states that the item is not available if it's in the list, and it'll do it forever with this list. You should use an if instead of a while. The script should look something like this:
inp = io.read()
if not (inp == "fish" or inp == "porkchop" or inp == "steak") then
write (inp)
write " is not available to order\n" -- added the \n here so that it makes a new line
sleep (30)
os.reboot()
end
Also, a nice tip, you can use a table to find if your input is available to order, instead of a list of if statements.
local items = {
fish = true,
porkchop = true,
steak = true
}
inp = io.read()
if not items[inp] then
write (inp)
write " is not available to order\n"
sleep (30)
os.reboot()
end
Thank you :D/>