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

Machini5t

Members
  • Content Count

    2
  • Joined

  • Last visited

Posts posted by Machini5t

  1. First, I love the Mod.


    I use this mod to replace the CC variety because CC doesn't work well with my mod selections.OC is far better anyway.


    So I set out to learn LUA programming yesterday, and read lots of API's and looked at lots of code.


    I discovered that direct interaction with the robot means I need to be in the LUA prompt and to run the LUA scripts I make, I have to be in the shell.. this wasn't immediatly obvious and it took me a bot to figure that out.


    Once I got the jest of how a LUA program for OC is put together, i started my first program last night and I got something that works but I have a bug that I can't track down, so I assume it's because I'm not allowed to have beginners luck.


    The program is a simple tree felling program. the steps are simple:


    Plant the saplings


    move 1 space up


    wait for the tree to be detected


    drop 1 block down


    chop the tree from bottom to top and back down.


    rinse an repeat.


    However, after the robot plants the saplings, it is just 1 block away like this: Rss


                                                                                                                             ss


    First issue:


    The saplings never grew. wide open sky, nothing above.


    I moved the robot back from the saplings so there is a space between the robot and the first sapling, but this means the robot cannot detect the grown sapling from 2 blocks away.


    I thought i'd add a timer to move the Robot forward 1 space to detect every 15 seconds and if it detected the tree, it would drop down 1 space, move forward one space and fell the tree as usual.


    Second issue:


    The second problem I had was after several trees were felled, the robot would lose track of the height variable so, while the robot was felling the second half of the tree, it would continue to dig into the ground as much as 5 blocks and muddle in that hole.


    This bug seems random. and my thought is that the timer I added but be interfering with the height count?.. but being new to LUA and OpenComputers mod and programming in general.


    Would anyone mind giving a guy a hand to *fix this second issue?


    I will include my program code here:


    [Edit] just realized how shabby the code looks at the end where I was working last. apologies.



    local robot = require("robot")
    local sides = require("sides")
    local event = require("event")
     
    local height = 0
     
    function Harvest()
        robot.swing()
        robot.forward()
        robot.swing()
     
        while robot.detectUp() do
          robot.swingUp()
          robot.up()
          robot.swing()
          height = height + 1
        end
     
        robot.turnRight()
        robot.swing()
        robot.forward()
        robot.turnLeft()
     
        for i = 1,height do
          robot.swing()
          robot.swingDown()
          robot.down()
        end
     
        robot.swing()
        robot.turnAround()
        robot.forward()
        robot.turnRight()
        robot.forward()
        robot.turnRight()
        Saplings()
    end
     
    function Saplings()
        if not robot.detect() then do
          robot.select(12) -- Saplings here
          robot.forward()
          robot.place()
          robot.turnRight()
          robot.forward()
          robot.turnLeft()
          robot.place()
          robot.turnAround()
          robot.forward()
          robot.turnAround()
          robot.place()
          robot.turnLeft()
          robot.forward()
          robot.turnRight()
          robot.place()
          robot.up()
     robot.back()
     event.timer(15,onTimer,20)
    end
      end
    end
     
    function onTimer()
    robot.forward()
    if robot.detect() then
    Harvest()
    else
    robot.back()
    end
     
    end
    -- event.timer(30, onTimer, 50)
     
    Saplings()

  2. In  v1.3.0 Beta 1, while attempting to assemble a robot, it is pleasant to get a list of items needed to complete the project.

    I am wondering though, where can I place the Screen that is required to interact with my Robot?

    edit: Seems being in creative mode had spoiled me. the Robot only needs a tier 1 monitor and it fits into any of the 9 upgrade slots.

     

×
×
  • Create New...

Important Information

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