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

Universal turtle inventory hlep.

Started by CupricWolf, 06 March 2013 - 08:41 PM
CupricWolf #1
Posted 06 March 2013 - 09:41 PM
Hi,
I'm trying to update some programs I have modified (sdbuild that does cylinders and has a progress bar to be specific) to work with both 1.4+ turtles and 1.3- turtles. I have already figured out how to make my progress bar be independent of terminal width. My current problem is that the two versions have differing numbers of inventory slots. I looked on the wiki and it said
turtle.select(slotNumber)
will return true if slotNumber is > 9 so I thought I could use that to tell if I'm running in 1.3- or 1.4+

if turtle.select(16) then
-- is 1.4+
else
-- is 1.3-
end
All that did though was throw an error "Slot number 16 out of range" on a turtle in 1.3.x (Tekkit). My question then is, Is there some way that I can tell weather or not the turtle has 9 or 16 slots? Any help would be much appreciated.
Best Regards,
Happydude11209
immibis #2
Posted 06 March 2013 - 09:46 PM
Use pcall to detect errors.


if pcall(turtle.select, 16) then
  -- it worked fine and didn't raise an error
  -- this code doesn't tell you if it returned true or false, but it is possible to detect that
else
  -- it errored. the error won't be displayed on the screen since pcall caught it.
end
CupricWolf #3
Posted 07 March 2013 - 05:32 AM
Thank you very much! As far as I can tell this worked. I only wanted to know if turtle.select() returned true or false because I thought I could use false to mean 1.3- and true to mean 1.4+ but pcall() replaces the need for that, so I don't need to know what turtle.select() returned. I am now using


invEnd = 9
if pcall(turtle.select, 16) then
invEnd = 16
else
invEnd = 9
end
remiX #4
Posted 07 March 2013 - 05:37 AM
All you need to do is
local version = os.version():gsub( "TurtleOS ", "") -- or whatever it says on a turtle, lol forgot :D/>
print(version)

--Output:
1.5 -- or whatever version you're using
-- then use this with tonumber(version) to compare it with another number

if tonumber(version) < 1.5 then
	print( "Old version!" )
else
	-- valid
end