Posted 19 May 2013 - 07:37 AM
Hi People,
I am using CC on MC 1.4.7 with Miscperipherals and I am trying to build a nice code for enchanting with the xp turtles. Now, the problem where I run in to is that I want to build in a failsafe system. I am using a while true do loop to keep the program looping. Now my problem is that when you put a non enchantable (or no item) in it will exit the program when you try to enchant. Now that is understandable because the m.enchant() function will return false instead of true and so it will exit the loop. At least, so I thought…
code:
I tried putting in some stuff after the loop would finish:
And even later on Irealised functions are seen as a variable so I tried this:
But it still exits the program without showing the text or clearing the terminal… Does the m.enchant() function make the program stop if it fails? Or what am I missing here?
I am using CC on MC 1.4.7 with Miscperipherals and I am trying to build a nice code for enchanting with the xp turtles. Now, the problem where I run in to is that I want to build in a failsafe system. I am using a while true do loop to keep the program looping. Now my problem is that when you put a non enchantable (or no item) in it will exit the program when you try to enchant. Now that is understandable because the m.enchant() function will return false instead of true and so it will exit the loop. At least, so I thought…
code:
Spoiler
function GetLevels()
m=peripheral.wrap("right")
local Levels = m.getLevels()
print("There are ".. Levels.." levels stored")
end
function Enchant()
term.clear()
term.setCursorPos(1,1)
select(1)
GetLevels()
print("Enchanting item at Which Level?")
m=peripheral.wrap("right")
local LVLS = tonumber(m.getLevels())
local EnchantLVL = tonumber(read())
if EnchantLVL > LVLS then
print("Cannot enchant, not enough Levels available.")
sleep(2)
else
m.enchant(EnchantLVL)
print("Enchanting succeeded, please check your item.")
sleep(3)
end
end
while true do
term.clear()
term.setCursorPos(1,1)
print("To enchant an item, place it in slot 1 and press any character key...")
os.pullEvent("char")
Enchant()
end
I tried putting in some stuff after the loop would finish:
Spoiler
function GetLevels()
m=peripheral.wrap("right")
local Levels = m.getLevels()
print("There are ".. Levels.." levels stored")
end
function Enchant()
term.clear()
term.setCursorPos(1,1)
select(1)
GetLevels()
print("Enchanting item at Which Level?")
m=peripheral.wrap("right")
local LVLS = tonumber(m.getLevels())
local EnchantLVL = tonumber(read())
if EnchantLVL > LVLS then
print("Cannot enchant, not enough Levels available.")
sleep(2)
else
m.enchant(EnchantLVL)
print("Enchanting succeeded, please check your item.")
sleep(3)
end
end
while true do
term.clear()
term.setCursorPos(1,1)
print("To enchant an item, place it in slot 1 and press any character key...")
os.pullEvent("char")
Enchant()
end
term.clear()
term.setCursorPos(1,1)
Print("Something went wrong with enchanting, please check your item and restart the turtle.")
And even later on Irealised functions are seen as a variable so I tried this:
Spoiler
function GetLevels()
local Levels = m.getLevels()
print("There are ".. Levels.." levels stored")
end
function Enchant()
term.clear()
term.setCursorPos(1,1)
select(1)
GetLevels()
print("Enchanting item at Which Level?")
local LVLS = tonumber(m.getLevels())
local EnchantLVL = tonumber(read())
if EnchantLVL > 30 then
print("Cannot enchant with more then 30 Levels.")
sleep(2)
elseif EnchantLVL > LVLS then
print("Cannot enchant, not enough Levels available.")
sleep(2)
elseif m.enchant(EnchantLVL) then
print("Enchanting succeeded, please check your item.")
sleep(5)
else
print("Enchanting failed, either there is no item in slot 1, or it is not enchantable.")
sleep(2)
end
end
m=peripheral.wrap("right")
while true do
term.clear()
term.setCursorPos(1,1)
print("To enchant an item, place it in slot 1 and press any character key...")
os.pullEvent("char")
Enchant()
end
But it still exits the program without showing the text or clearing the terminal… Does the m.enchant() function make the program stop if it fails? Or what am I missing here?