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

how to get my turtle to print level

Started by jakemg, 11 May 2013 - 05:57 PM
jakemg #1
Posted 11 May 2013 - 07:57 PM
whats the code to get my turtle to print its level?
and how do i get it to coolect xp
SuicidalSTDz #2
Posted 11 May 2013 - 08:45 PM
Well, this is from the mod MiscPeripherals so you should probably state that in the main post. However, I have used this mod regularly and know how everything works to an extent.

RichardG867 said:
XP Upgrade
Craft a Turtle alongside an Enchantment Table to get a XP Turtle. It is able to store XP and enchant items using the stored levels.
Exposes the following functions:
  • add(amount): Adds XP from XP bottles or monster eggs, using amount (optional, defaults to as much as possible) of the item in the current slot. Returns the amount of XP added.
  • get(): Returns the total amount of XP on the turtle.
  • getLevels(): Returns the amount of XP levels on the turtle.
  • collect(): Collects XP from XP orbs on the ground in a 2 block radius around the turtle. Returns the amount of XP collected.
  • setAutoCollect(autoCollect): If autoCollect is true, allow the turtle to automatically collect XP periodically.
  • enchant(levels): Enchants the item in the current slot using the specified levels. Returns true if successful, false if not.
  • get/getUp/getDown(): Gets XP from the following XP sources:
    • Other XP turtles
    • Furnaces, IC2 Iron Furnaces and Induction Furnaces, Thermal Expansion Powered Furnaces (sucking the item in the output slot(s))
    • Thaumcraft Brain in a Jar
    Returns the amount of XP obtained.

So, now that we know the correct commands, let's get started:

First you must wrap the peripheral, which for all of his items are on the right of the turtle, so let's do that first:
local m = peripheral.wrap("right")
Ok, now we can interact with the XP upgrade on the turtle. Let's print out it's current XP level, which should be zero.
print(m.getLevels())
Now, let's just print out the amount of XP orbs the turtle is currently storing
print(m.get())

Now that we have all your basic methods down, let's talk about collecting then send you on your merry way:

For collecting you can either repeatedly call the m.collect function or you can call m.setAutoCollect(true) at the top of your program to have the turtle repeatedly collect nearby XP orbs until he is restarted.

collect()
m.collect()

and lastly, setAutoCollect() (Remember, this is to go at the top of your program)
m.setAutoCollect(true)
The argument for setAutoCollect() must be a boolean (true or false). If you wish to stop auto-collecting, simply do this:
m.setAutoCollect(false)
Or, you can simply restart the turtle