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

then expected problem [Solved]

Started by julllleee, 30 March 2013 - 02:41 AM
julllleee #1
Posted 30 March 2013 - 03:41 AM
Hi, Im trying to get a code to work but i can't figure out what the problem is.
this is the code


exp = peripheral.wrap("right")
a = 1

function Ko()
sleep(1)
a = a+1
if a = 150 then os.reboot()
else if redstone.getInput("top") == true
then exp.collect()
turtle.attack()
Ko()
else
turtle.attack()
Ko()
end
end

Ko()

everything worked until i added the a = * thing. I added that because after the computer have run the script like 200 times it crashes, so i want it to reboot before that.

Thanks in advance!

P.S collect() is a code from another mod so that is not what is causing the problem

edit. nvm found out that the problem was a = 150 i should be a == 150
PixelToast #2
Posted 30 March 2013 - 04:40 AM
(i know the error is solved)
your using recursion
NEVER call a function within itself
use loops:

exp=peripheral.wrap("right")
while true do
sleep(1)
if redstone.getInput("top") then
  exp.collect()
  turtle.attack()
else
  turtle.attack()
end
end
i know you had a count thing to reboot before it would error but loops are more efficent