Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal

XenizedKitsune

Members
  • Content Count

    5
  • Joined

  • Last visited

Posts posted by XenizedKitsune

  1. And with that last addition, everything is working perfectly! Thank you so much, Finger and Molinko!

     

    If anyone wants my set up for auto-harvesting Pam's Harvestcraft trees, including the prep and robot code, let me know. Until then, best of luck to you all!

  2. Once again, Molinko, you're a lifesaver. The function works beautifully. I don't need it to be elegant or more condensed/complicated if it works exactly as intended, so you did wonderfully.

     

    As with all coding, the moment you think you have it all down perfectly, another bug shows up. This time, I think I'm just missing some kind of break.

    Right now, as soon as the robot gets a redstone signal, it'll run its farming operation. Which is fine, until it completes the operation. Instead of waiting for another redstone signal, it repeats the operation again, ignoring the signal or lack thereof.

    I ran a separate test trying out a "do return end" line, but that ended the program entirely, which I don't want. (A farm isn't helpful if it turns off until I manually restart it every time).

    Where would I need a break/return to get it back to looking for that signal, and how would it be coded?

    For reference, here's the code I have thus far, minus the manual pathing I put in to navigate the farm.

    local robot = require("robot")
    local sides = require("sides")
    local event = require("event")
    local component = require("component")
    local function forward(times)
      times = times or 1
      local success, reason, moves = false, nil, 0
      for move = 1, times do
        success, reason = robot.forward()
        if not success then break end
        moves = moves + 1
      end
    end
    
    while true do
      local e, addr, side, prev, current = event.pull("redstone_changed")
      if e and side == sides.back and prev == 0 then
        robot.farmTrees -- # Here's where I've got a ton of manual guidance. Thanks for the random spawns, Pam
        -- # Right here is where I would think a break or return goes.
      end
    end

    Looking back, it may help to use the redstone card component to look for a signal after it's done farming... if it doesn't get any, then break the sequence. And if there is a signal, my tree farm is ready to be harvested anyway, so it'll get back to work.

    A simple test where the robot bounces up and down whenever it reads a signal of 1 (after Super Circuit Maker subtracts 14 from a lever's signal)  confirmed that I can make it work whenever it gets a signal. The robot stopped bouncing when I flipped the lever off, dropping the signal to 0.

    After I get some sleep tonight, I'll try replacing the event.pull("redstone_changed") group with the code I came up with and see if I break anything.

    I'll leave the code for my redstone test here in case anyone from outside my timezone can help an amateur like myself out.

    local component = require("component")
    local sides = require("sides")
    local robot = require("robot")
    
    while true do
      if component.redstone.getInput(sides.back) == 1 then
        robot.up()
        robot.down()
      end
    end
    -- # Lever on, robot bounces like a ball. Lever off, robot stops on the floor.
    -- # Though for some reason Ctrl+Alt+C won't kill the command, so I have to shut down the bot to stop the .lua from running.

    I'll look into how the redstone card works again, but I would appreciate any help figuring out how to break out of the loop without shutting the program down entirely.

  3. 1 hour ago, Molinko said:

    I'm not really sure what you meant by that...

    I was simply wondering how functions worked in OpenComputers. It would have been cool if I could crunch my harvest routine into a function so I don't have to hit tab twice after every single line.

    Due to the random nature of the fruit spawns on each tree, there's nothing repetitive in my code, so functions aren't totally necessary. Thank you for the example, though.

     

    Okay, I'm ALMOST done with the code, but there is one last issue that may save me a few dozen lines. How can you make a robot move more than one block in a single line?

    It won't stop in a block occupied by a fruit, but players can pass directly through them. Theoretically, so can robots, if its destination is beyond the fruit... I hope?

    (Plus running between two different trees means putting in 'robot.forward()' half a dozen times and that feels so crude...)

  4. SUCCESS! The robot has harvested a vanilla bean when I pushed a button! Thank you so much, Finger!

     

    The next step now is to teach the robot to equip bonemeal, though that SHOULD be relatively easy... Possibly something like

    local bonemeal = require("component")
    
    bonemeal.inventory_controller.equip

    Or maybe I need to require just "component"? Trial and error may help.

    Just needed to require "component". Trying to have it require "inventory_controller" as well gave me... quite the long error message as it looked through every single folder in the 'bot.

     

    And as a final note, do functions work in OpenComputers? I can see they're a thing in real Lua, but I've yet to see any mention of functions in OpenComputers tutorials... They could help me clean up my code some.

  5. In my Sky Factory 3 world, I would like to fully automate a farm for the Pam's Harvestcraft crops and trees. The problem became how to automate harvesting the nuts/fruits (since EnderIO and similar mods just break the trees). I didn't want to line an orchard with mechanical users, so I turned to OpenComputers after noticing I can program a robot to do it for me.

    I've spent the past few days trying to learn how to build/program a robot, and finally managed to harvest vanilla at all (by jamming a bunch of move and use commands in one .lua ). The next step was suppose to make it react to a redstone signal (starting its harvest routine when a chest of bonemeal is full, thank you Storage Drawers).

    However, I can NOT for the life of me figure out how to make a robot react to a redstone signal AT ALL. Even something as simple as printing "true" when it gets one. All the tutorials/help I can find are either 1) Saying what a redstone card is at all, not how to use it,  2) Incomplete snippits of code for a computer system, (which gives me lots of errors when I try to add them into my robot. Could be my incompetence, but that's beside the point) or 3) for ComputerCraft. I only just picked up OpenComputers and Lua 2 days ago, I don't know how to translate ComputerCraft code into OpenComputers code.

     

    Any help figuring out how redstone cards work in robots would be greatly appreciated. (And of course any tips on how to make a robot sleep/wait until it gets a redstone signal, then spring into action, would fantastic.)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.