Debugged and Ready for Polish

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am updating my progress on my LootRepair program. Let’s get started.

It wasn’t easy, but I finished pulling the crippling bugs out of my program. Using the turtle’s actual state as the program’s state was a good call. It can more easily handle an unexpected situation and sometimes auto-correct in the case of a minor inefficiency, like when I was missing a line of code to select slot 1 before crafting.

I think the biggest bug I had was my use of an OR statement. The line was:

elseif state == “good2” or “new2” then

I thought the logic was

IF state MATCHES (EITHER “good2” OR “new2”) THEN DO THIS CODE.

When it was more like,

IF (state MATCHES “good1”) OR (“new1” ISN’T false) THEN

Note the elseif statement. I had two such options in my huge list of things to do. I ended up just removing all traces of the “new” states  since they did exactly the same thing as the “good” states.

Another bug I pulled out involved confusion over bitwise operations. I was having trouble with what I thought was the “correct” way to bitshift a set of 2 bit flags for comparison; the exact required steps of which escaped me, so I pulled a programmer’s trick and did it slightly differently, by shifting the flag to be read to the 1’s and 2’s places, instead of moving the mask reading the code.

Pulling that tough bug was an interesting journey, taking up a couple days. For a while, I thought it was a problem with the limitations of the 80’s style computing model (tiny floppies can get filled up when you have about 5 backup copies of a program with 200-300 lines of code.) I had it printing the program state from a variable at each elseif statement for handling the state, but it was only after I appended a hard-coded confirmation of the state that I spotted the error.

With the prototype program thoroughly tested and (hopefully) debugged, I set it to work on four turtles. The good news is that they can work, but the bad news is that they still need someone to check in from time to time; one of the turtles keeps losing track of the item it’s supposed to repair. I haven’t even tried to tackle that one yet.

My program is almost ready. Once I finish this round of it, I plan on redoing the melee turtles under the same state-do something model. If I’m bored and don’t have anything else to do, I may even look into redeveloping this into either a custom API or framework (I’m not sure what the proper word is here).

Final Question: ComputerCraft has been perfect for getting into coding, but I feel I’ve been lacking in the presentation of actual code. Any idea on how you’re supposed to denote that with WordPress?

Leave a Reply