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

Reading additional return information

Started by Jafremek, 15 December 2013 - 05:30 PM
Jafremek #1
Posted 15 December 2013 - 06:30 PM
In the lua prompt, if you run turtle.suck() for example, it shows either true or shows false with a reason for the failure "No space for items" or "No items to suck".

Is there a way to distinguish between failure reasons with the running program?
Lyqyd #2
Posted 15 December 2013 - 08:59 PM
Probably something like:


local success, failureReason = turtle.suck()
awsmazinggenius #3
Posted 15 December 2013 - 09:04 PM
And then this:

local succeeded, reason = turtle.suck()
if succeeded then
  print("Succesfully collected item(s).")
else
  print("Failed for the following reason:")
  print(reason)
end

Lua has multiple assignment support.
Edited on 15 December 2013 - 08:04 PM
Jafremek #4
Posted 15 December 2013 - 09:41 PM
That's the part that was missing. Thanks a bunch.