Jump to content




Debugging?


  • You cannot reply to this topic
5 replies to this topic

#1 Lost Ninja

  • Members
  • 39 posts

Posted 11 October 2012 - 01: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?

#2 Lettuce

  • Members
  • 210 posts
  • LocationIn your fridge.

Posted 11 October 2012 - 02: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

#3 Lost Ninja

  • Members
  • 39 posts

Posted 11 October 2012 - 02: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 by Lost Ninja, 11 October 2012 - 02:34 AM.


#4 Lettuce

  • Members
  • 210 posts
  • LocationIn your fridge.

Posted 11 October 2012 - 02: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.

#5 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 11 October 2012 - 02: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)


#6 Lost Ninja

  • Members
  • 39 posts

Posted 11 October 2012 - 04: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users