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

Debugging?

Started by Lost Ninja, 11 October 2012 - 12:43 AM
Lost Ninja #1
Posted 11 October 2012 - 02:43 AM
Is it possible to enable some sort of step through mode for debugging purposes?

This afternoon I wrote a simple tunnelling program but managed to delete the world losing the script (that won't happen again), I've just re-typed it using the same written notes (PnP) and my turtle goes berserk. Now the version I wrote this afternoon had a debugging line after each exectution so I could see in real time what it thought it was supposed to be doing… I'm going to re-add that now but it would be nice if I could just have it step through each step of the program slowly (or with user input).

Any ideas?
Lettuce #2
Posted 11 October 2012 - 03:05 AM
How about os.pullEvent("key") ? That makes the turtle/computer freeze and wait for you to press a key. Any key, in this case. Be more specific if you need something specific, but that should generally work, albeit tediously.

–Lettuce
Lost Ninja #3
Posted 11 October 2012 - 03:28 AM
Thanks, not sure how to do that so I was working on a different system but it doesn't seem to work as I'd expect it.
local function test(txt)
	if dbg== 1 then
		print("Turtle says" ..txt.. )
		sleep(2)
	end
end

Called with:
test("Moving Forward")

Works fine if I remove the ..txt.. but without that it's pretty pointless…

edit edit:

Ignore me got it… now all I have to do is work out where I effed up the instructions… :/
Edited on 11 October 2012 - 01:34 AM
Lettuce #4
Posted 11 October 2012 - 03:49 AM
It seems txt is supposed to be user-inputted text? Why include it as an argument? It would work just fine without it if txt is a variable. Also, I don't concatenate often, so I may be wrong, but I don't think you need the last two dots. ..txt should work, unless you want to concatenate another variable too.
Luanub #5
Posted 11 October 2012 - 03:54 AM
Just in case someone else is having this issue the problem is here

print("Turtle says" ..txt.. )


--it should be
print("Turtle says "..txt)
--or
print("Turtle says ",txt)
Lost Ninja #6
Posted 11 October 2012 - 05:40 AM
Ah yeah should have added my solution of course, I used the 2nd of the two you posted.

txt is the argument passed when I call the function an example being "Mining Forward". So every time the turtle does the mining forward function (tryDig) it is supposed to send a message that it is mining forward… Of course then I had the issue of where in the nested if/while/etc function to place those test functions and I never got it right. However I did get the program to work. I'd missed out a couple of move commands… ;)/>/>

Now I need to work out how to make it pop down a chest and dump stuff… I mean I know the individual commands but haven't worked out how to link them together yet. :)/>/>

Fun fun fun… :P/>/>

TY All for the help.