Turtle Program Rewrite

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

Last week, I left off with my discovery of the failed premise of my first program. It works well enough if treated properly, but the core function, turtle.craft(), didn’t behave as nicely as I would have hoped in unexpected situations. My whole design philosophy was

1. Wait for an item to be shoved in
2. Make sure everything was all good to craft
3. Craft
4. Output
5. Check inventory for any more items to evaluate
6. Repeat

Problems arose when too many items clogged up in the turtle inventory at once. My new design will focus around a turtle opening itself up for an item when it’s ready and closing itself up again when one arrives. Hoppers shut off when powered, so I’m going to have the turtles follow the same protocols. While I’m at it, I want to make a second signal so the turtles can activate an error mode and turn on a light when there’s a problem.

This re-write, I want to actually write my program in such a way that it will be a versatile, well written program. Good code is easier to maintain, though it might be harder to write at first.

I started the rewrite by opening Notepad++, an awesome plaintext editor for Windows, and wrote my program in what was supposed to be pseudocode, but ended up growing into attempted proper Lua. Funny how a better tool can clear the head, because the editor that came with ComputerCraft does not have cut and paste, and when I developed several functions and wanted to order them according to other functions each one calls, retyping a chunk of code longer than a few lines gets a bit discouraging.

I transferred the files to the server computer and onto the very in-game disk I was using for my computer setup. Once again, I ended up in the same low-end, default editor for debugging my program. Admittedly, my program is still incomplete. At this point, I’m not even sure if it has the “next item” code correct.

One thing I do like about my working prototype program is how I can hot swap items… I just had an idea, but implementing it might involve rewriting the way it’s supposed to work, but maintenance should be a bit easier. Right now, I have the turtle’s state follow a cascade controlled by a series of spaghetti-code if-then statements. My new idea would have the main loop get the turtle’s state each event and act on that. I don’t even know if it’s reasonable. Honestly, I think I should be fine with my working prototype and another turtle to regulate the item speed, but I want to publish my code here.

Final Question: A good artist of any discipline should be able to work with any set of tools they have to work with. When you don’t care about formatting, or wish to avoid it, what plaintext editor do you use?

Leave a Reply