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

Melon Dispenser 5000 -WIP-

Started by Mr. Fang, 20 December 2012 - 08:06 AM
Mr. Fang #1
Posted 20 December 2012 - 09:06 AM
EDIT* Help I run this and get:
startup:32: attempt to compare number with string expected, got number.

Can Anyone help me out?


I started this code yesterday was unsure if it would fully work. I plan to place a couple of computer/dispenser machines around spawn to sell melons. Basically it would work like a soda machine, only instead of costing money you could just enter your name. I know that anyone with the passcode could fake their name, but whatever. I'm not too strict on whether the name is legit or not. I just need special attention around the line where I run the redpulse and the line where I change the amount entered into a usable number.
For my Pastebin people: http://pastebin.com/kdSV2Gf5



--Code that dispenses melons while logging names and numbers for later reading
os.pullEvent = os.pullEventRaw
textutils.slowPrint("MelonDispenser 5000")
textutils.slowPrint("Made by FangCo. ")
textutils.slowPrint("Please Enter Your Name.")
name = read()
if name == "admin" then
print("Admin Recognized!")
print("Please Enter Your Passcode!")
passcode = read("*")
   if passcode == "danrocks" then
   print("Access Granted!")
   sleep(3)
   term.clear()
   term.setCursorPos(1,1)
   else
   print("Incorrect Passcode!")
   sleep(3)
   os.reboot()
   end
else
term.clear()
term.setCursorPos(1,1)
print("Welcome "..name.."! ")
textutils.slowPrint("Please Enter Your Passcode!")
pass = read("*")
   if pass == "cake" then
   print("Passcode Correct "..name.."!")
   print("Please Enter Desired Amount (below 32)")
   amount = io.read()
   amount = tonumber(amount)
   max = 32
   min = 1
	 if amount > max then
	 print("Sorry Number too High! Try Again!")
	 sleep(3)
	 os.reboot()
	 elseif amount < min then
	 print("Sorry Number Too Low!")
	 sleep(3)
	 os.reboot()
	 else
	 print("Ok! Depositing "..amount.." to the right!")
	 shell.run("redpulse", "right", ""..amount.."", ".5")
	 print("Have a Nice Day!")
	 log = fs.open("logbook", "a")
	 log = fs.writeLine(" "..name.." entered the passcode and received "..amount.." melons!")
	 sleep(4)
	 os.reboot()
	 end
   else
   print("Sorry Incorrect Passcode!")
   sleep(4)
   os.reboot()
   end
end
Mr. Fang #2
Posted 20 December 2012 - 10:58 AM
did some changes, there may be differences between the pastebin and here, but this will be the Main Page that I edit on.
AfterLifeLochie #3
Posted 20 December 2012 - 11:12 AM
This has been moved to Ask A Pro - it's best to ask questions there, and not in the released Programs board.
Cranium #4
Posted 20 December 2012 - 11:12 AM

if amount > "32" then
You are comparing a number to a string. You need to change "32" to 32. Quotations denote strings, and you cannot compare numerical values to strings.
Mr. Fang #5
Posted 20 December 2012 - 11:28 AM

if amount > "32" then
You are comparing a number to a string. You need to change "32" to 32. Quotations denote strings, and you cannot compare numerical values to strings.

Thanx I found that out shortly after using the tutorial on the wiki for "guess the number"… I just sorta ended up using variables instead. I'll probably set them earlier though so I can config the program faster in-game.

I've already fixed the code and it works nicely. I'll probably post this to Programs tomorrow then…