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

[HELP]3x3 Mobtrap turtle program[HELP]

Started by Modernkennnern, 12 October 2012 - 03:17 PM
Modernkennnern #1
Posted 12 October 2012 - 05:17 PM

function Attack()
for i = 1,3 do
if not turtle.attack() then
	   turtle.forward()
   end
end
function MoveAttackLeft()
Attack()
Turtle.left()
turtle.forward()
turtle.left()
   end
end
  
MoveAttack()
MoveAttack()
MoveAttack()
	  
function MoveAttackRight()
Attack()
turtle.right()
turtle.forward()
turtle.right()
end

the error is: "mobtrap:17: attempt to call nil

anyone know what the problem is, I would appreciate it :)/>/>

(I am new to computers)
Doyle3694 #2
Posted 12 October 2012 - 05:24 PM
Where are you declaraing the function MoveAttack?
Modernkennnern #3
Posted 12 October 2012 - 05:27 PM
Where are you declaraing the function MoveAttack?

very good question :)/>/>
I changed the name without changing the code :)/>/>



 
function Attack()
for i = 1,3 do
if not turtle.attack() then
	   turtle.forward()
   end
end
function MoveAttackLeft()
Attack()
Turtle.left()
turtle.forward()
turtle.left()
   end
end
  
MoveAttackLeft(3)
	   
function MoveAttackRight()
Attack()
turtle.right()
turtle.forward()
turtle.right()
end
MoveAttackRight(3)
   end
end


changed the code a little,now I get: " bios:206: [String "mobtrap"]:30: '<eof> ' expected
Doyle3694 #4
Posted 12 October 2012 - 05:29 PM
Then I know I'm not the only one dumb enough to do stuff like that :)/>/>
Modernkennnern #5
Posted 12 October 2012 - 05:34 PM
Then I know I'm not the only one dumb enough to do stuff like that :)/>/>

incase you didn't notice, I updated the reply if you can help me more :)/>/>
Doyle3694 #6
Posted 12 October 2012 - 05:37 PM
'<eof>' expected means you have 1 too many ends :)/>/>
Modernkennnern #7
Posted 12 October 2012 - 05:39 PM
'<eof>' expected means you have 1 too many ends :)/>/>
yes, I know, but where? :)/>/>
Doyle3694 #8
Posted 12 October 2012 - 05:44 PM
plus, you didn't make your MoveAttackLeft() funciton accept arguments, so putting a 3 in there does nothing. change your MoveAttackLeft() funciton to something like this:

function MoveAttackLeft(times)
for i=1,times
Attack()
turtle.left()
turtle.forward()
turtle.left()
end
end


Doyle3694 #9
Posted 12 October 2012 - 05:48 PM
wow ends are messed up in your code, I'll fix it…..

function Attack()
   for i = 1,3 do
      if not turtle.attack() then
         turtle.forward()
      end
   end
end

function MoveAttackLeft(times)
   for i=1,times
      Attack()
      turtle.left()
      turtle.forward()
      turtle.left()
   end
end

  
MoveAttackLeft(3)
           
function MoveAttackRight(times)
   for i=1,times
      Attack()
      turtle.right()
      turtle.forward()
      turtle.right()
   end
end

Lyqyd #10
Posted 12 October 2012 - 05:52 PM

function Attack()
  for i = 1,3 do
    if not turtle.attack() then
      turtle.forward()
    end
  end
end

function MoveAttackLeft()
  Attack()
  turtle.left()
  turtle.forward()
  turtle.left()
end

MoveAttackLeft()
	   
function MoveAttackRight()
  Attack()
  turtle.right()
  turtle.forward()
  turtle.right()
end

MoveAttackRight()

Corrected code. Removed the arguments to function calls that don't take arguments. Notice how it is easy to tell where you need end statements when you use proper indentation.
Modernkennnern #11
Posted 12 October 2012 - 05:57 PM
Thanks :)/>/>
Doyle3694 #12
Posted 12 October 2012 - 06:05 PM
Get Ninja'd, Lyqyd! Because it matters, yes.