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

My Enchanting Program : XP Turtle

Started by TechGuy427, 07 April 2013 - 06:45 AM
TechGuy427 #1
Posted 07 April 2013 - 08:45 AM
This is my program, I'm using the XP Turtle to auto collect XP in a different program, that works but this is my second program for user input to use the XP stored but line i don't know why it dosen't work? help please :/ Very gratefull :)/> thanks alot to any responses :D/> Line 16 crashes, says it should be a number
||||| Pastebin : http://pastebin.com/NZsLa53u |||||



[indent=1]function GetLevels()[/indent]
[indent=1]m = peripheral.wrap("left")[/indent]
[indent=1]local Levels = m.getLevels()[/indent]
[indent=1]print("There are "..Levels.." levels stored")[/indent]
[indent=1]end[/indent]

[indent=1]function EnchantFunction()[/indent]
[indent=1]print("Would You like to enchant an item?")[/indent]
[indent=1]local EnchantTrue = "Yes"[/indent]
[indent=1]local input = read()[/indent]
[indent=1]if input == EnchantTrue then[/indent]
[indent=1]print("Place item in slot 1")[/indent]
[indent=1]select(1)[/indent]
[indent=1]print("Enchanting Slot 1 At Which Level?")[/indent]
[indent=1]local EnchantLevel = read()[/indent]
[indent=1]m.Enchant("EnchantLevel")[/indent]
[indent=1]else[/indent]
[indent=1]print("You have not chosen to enchant, restarting")[/indent]
[indent=1]term.clear()[/indent]
[indent=1]term.setCursorPos(1,1)[/indent]
[indent=1]end[/indent]
[indent=1]end[/indent]

[indent=1]GetLevels()[/indent]
[indent=1]EnchantFunction()[/indent]
jakemg #2
Posted 07 April 2013 - 09:11 PM
wrong section bud :P/> try ask a pro nice program btw
theoriginalbit #3
Posted 07 April 2013 - 09:17 PM
For next time, please use [code][/code] tags around your code, and as jakemg stated post it in "Ask a Pro"…

As for your problem…
Firstly, with this line

select(1)
I think you mean

turtle.select(1)

now the actual problem…. this is your line #16

m.Enchant("EnchantLevel")
EnchantLevel is your variable that you read the input from the user. however here you are giving the 'Enchant' function a string that says "EnchantLevel", I think you meant to do

m.Enchant(EnchantLevel)
that way what the user types will be given to the 'Enchant' function. however from my very limited knowledge of the peripheral you are using, and given the error message it wants a number, not a string, which is what the 'read' function returns. So you need to convert the number the user has entered from a string, to a number like so

m.Enchant(tonumber(EnchantLevel))
TechGuy427 #4
Posted 11 April 2013 - 11:05 AM
For next time, please use [code][/code] tags around your code, and as jakemg stated post it in "Ask a Pro"…

As for your problem…
Firstly, with this line

select(1)
I think you mean

turtle.select(1)

now the actual problem…. this is your line #16

m.Enchant("EnchantLevel")
EnchantLevel is your variable that you read the input from the user. however here you are giving the 'Enchant' function a string that says "EnchantLevel", I think you meant to do

m.Enchant(EnchantLevel)
that way what the user types will be given to the 'Enchant' function. however from my very limited knowledge of the peripheral you are using, and given the error message it wants a number, not a string, which is what the 'read' function returns. So you need to convert the number the user has entered from a string, to a number like so

m.Enchant(tonumber(EnchantLevel))

Wow, this fixed it, thanks a bunch… i fixed the small problems like the turtle.select(1) and others, this really helped out! thanks!