lootRepair0.3

Good Morning from my Robotics Lab! This is Shadow_8472 and today, I am reviewing my progress on the lootRepair program from my previous two posts. Let’s get started.

I started this iteration of the program with a major paradigm shift. My first two attempts at the program could be modeled as following a coded track. I gave up when I had trouble tracking down too many bugs when I tried to break my second attempt.

My new version has two phases in its main loop: a getState phase, and an action phase. The getState phase takes a look at the turtle’s state, and the action phase acts on that phase, handling the upstream redstone output, weather or not to wait on an event, and there’s even a spot where I can put extra code; all of which were previously handled with multiple instances of redundant code, each copy of which had to be visited when a change was made to one of them. I think of it as a state machine, but I’m not exactly sure if that’s the proper name for it. Whatever the case, the debugged product should be able to handle me giving it more abuse with less patchwork.

Building up the code to check for a crafting table took four attempts before I came up with a version that wasn’t too ugly to follow, and then one still needs to know what they’re looking at. Early startup() attempts were based on “use the correct tool, turtle.getItemDetail(n)[“name”], and baby its weak spot, (possible crash from a nil return)” ideas, so I ended up using the slightly slower, but more ingenuitive approach, try to equip each item in the turtle’s inventory and see if it can craft if something equips. Keep track of if and where a workable slot is found, and try the other equipped slot. (There’s a bug where crafty turtles forget their crafting benches, but they work after unequipping and reequipping them.)

As of right now, I still need to finish debugging it. When I transferred my Notepad++ generated document and stuffed it in the ComputerCraft folder where executable programs are stored, I got a bunch of errors and wide gaps where lines of code should be, or more likely, they are some other character interpreted as a line feed. After all, the CC editor doesn’t use proper tabs, maybe something else is messed up.

I’ve been editing the original program in parallel as I debug the in-game version. It’s a little redundant, but I really want to publish this some time here, hopefully next week… if I don’t take a break and blog about something else.

Final Question: Do you know a lot about ComputerCraft? Why is the turtle glitching its crafting table away on chunk reload?

Leave a Reply