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

Boolean value randomly changes in program

Started by Zero_Burn, 30 April 2013 - 11:28 PM
Zero_Burn #1
Posted 01 May 2013 - 01:28 AM
Title: Boolean value randomly changes in program

I found a program online that was a bare bones 2x2 tree lumberjack program, I took it and added a few bells and whistles (args, special stuff for my specific case), cleaned up the code, etc. It has run perfectly fine for a while but recently the boolean that holds whether the tree is grown or not (isGrown) seems to randomly switch to true even if the tree isn't grown yet… this caused the turtle to decide it was a good idea to burrow to the center of the earth (until I put a special case to stop it). Now it just kind of tears up the 2x2 patch of ground the saplings are on.

TL;DR: The boolean variable isGrown in the following code (http://pastebin.com/scZHfMmT) seemingly randomly switches from false to true without any reason. I was hoping a fresh set of eyes could see what is going on…

Thanks in advance!
QuantumGrav #2
Posted 01 May 2013 - 12:23 PM
Line 69 in your program in this function:


function altCheckTree()
	    turtle.up()
isGrown = not turtle.forward()
if isGrown == false then
  repeat
		  turtle.back()
		  turtle.down()
   sleep(30)
   turtle.up()
   isGrown = turtle.foward()   -- This one here
  until isGrown == true
end --if
	    turtle.down()
end --growTree()

Is incorrect. the line should be:


isGrown = not turtle.forward()

exactly like the one a little ways before it. Remember proper spelling for "turtle.forward" and you should be fine I think. This might not be the only problem, but it was the only problem I caught looking through your code. Hope this helps!
Zero_Burn #3
Posted 01 May 2013 - 08:58 PM
Unfortunately, it did not… I don't know if the metadata of a fir sapling changes as it grows or something but it seems that is the only reason it could not work…

(also I found out that turtles + pneumatic tubes + barrels = deleted turtle… RIP Jack)
Zero_Burn #4
Posted 02 May 2013 - 08:05 AM
Aand it seems to be working fine now for some reason, I did the fix that was suggested (plus about a dozen debugging print(tostring(isGrown)) lines in the code) and it magically worked… somehow. Thanks for all the help!

Edit:
It seems to not actually work at all still… I don't know why it is changing, there is no reason for it to change. I have placed those debugging print commands and the place it changes is in checkTree… but there is only a compare command there? I don't how it is changing… It is definitely that somehow the item Fir Sapling is different than the placed Fir Sapling, I ran a simple test (just a compare command) and it does indeed say that the sapling in its inventory is different than the planted sapling… I don't think it has anything to do with my code now…