Advertisement
rdalkire

computercraft food farm 1.2.1

Aug 1st, 2014
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.29 KB | None | 0 0
  1. --[[ Farms X rows, trying to alternate
  2.   crops according to the reference
  3.   slots, which are the first
  4.   contiguous slots that have seeds.
  5.  
  6. Run it without params to see
  7.   the most basic instructions.
  8.  
  9. Download as "frm". If you're a new CC
  10.   user, viewing this script on a
  11.   webpage, here's how you would install
  12.   this script. At your farming turtle:
  13.   pastebin get cp7xVVZT frm
  14.  
  15. For more usage details see the HOWTO
  16.   file http://pastebin.com/41Y6A2Lw
  17.  
  18. To add push-button functionality, use
  19.   http://pastebin.com/NBEMghX8
  20.  
  21. A slow usage video playlist, even
  22.   suitable for computercraft beginners:
  23. https://www.youtube.com/playlist?list=PLURVSv4oO436mURWG6YJ8mU8O49DIHeJb
  24.    
  25. For further coding, and to report bugs,
  26.   there's a project set up for eclipse
  27.   & lua development tools here:
  28. https://github.com/rdalkire/computercraft-programs
  29.  
  30. NOTE: There are some globals constants.
  31.    One is to sleep GROW_WAIT minutes,
  32.    one to repeat MAX_REPEATS or until
  33.    out of fuel, and others below.
  34.  
  35. TODO/WIP:
  36. - Remember, if updates include the use
  37.     of newer computercraft features,
  38.     be sure to update the
  39.     documentation to match.
  40. - Refactor:  Add the use of a logically
  41.     independent runtime dead-reckoner,
  42.     and delegate all maneuvering to
  43.     that.  This should make the
  44.     existing code simpler.
  45. - Select the waiting time depending
  46.     on whether the reference slots are
  47.     same-crop gapless.
  48. - Add special melon/pumpkin slots,
  49.     handling.
  50. - Sugarcane
  51. - Cocoa beans, maybe.
  52. - Allow the turtle to start at right
  53.     corner, depending which way is
  54.     open.
  55. - Create a routine for automated field
  56.     creation, given flat grassy area,
  57.     a bucket and a source of water.
  58.     (separate script?)
  59. - MORE COMMENTS!  :-)
  60.  
  61. Copyright (c) 2014
  62. Robert David Alkire II, IGN ian_xw
  63. Distributed under the MIT License.
  64. (See accompanying file LICENSE or copy
  65. at http://opensource.org/licenses/MIT)
  66. ]]
  67.  
  68. local frm = {}
  69.  
  70. -- After this many seed slots
  71. -- as indicated by plntblCnt, run the
  72. -- consolidate() function
  73. local CONSOLIDATE_THRESHOLD = 3
  74.  
  75. -- How many rows between consolidations
  76. local CONSOLIDATE_FREQCY = 1
  77.  
  78. -- The wait time between beginning of
  79. -- each harvest, in minutes.
  80. local GROW_WAIT = 40
  81.  
  82. -- The number of times to farm the
  83. -- field, baring other constraints
  84. local MAX_REPEATS = 1
  85.  
  86. -- There needs to be this minimum seed
  87. -- per reference slot
  88. local MIN_REF = 2
  89.  
  90. -- For when fuel is unlimited:
  91. local DEFAULT_FUEL = 10000
  92. -- maximum row  length.
  93. local DEFAULT_MAX_LENGTH = 32
  94.  
  95. -- Initial slots indicate what items
  96. -- the user deems plantable.
  97. local plntblCnt = 0
  98.  
  99. local isMockUp = false
  100.  
  101. -- TODO in DEV, require directly
  102. --local turtle=require "mockTurtle"
  103. local turtle=turtle
  104. if not turtle then
  105.   turtle = require "mockTurtle"
  106.   isMockUp = true
  107. end
  108.  
  109. frm.getTurtle = function()
  110.   return turtle
  111. end
  112.  
  113. -- Initializes the Plantable Count.
  114. -- Called before any work is done, this
  115. -- finds the last populated inventory
  116. -- slot.  That and the ones below
  117. -- will be used as reference.
  118. -- @return plntblCnt
  119. local function initPlntblCnt()
  120.   -- To ensure it only runs once
  121.   if plntblCnt == 0 then
  122.     local indx = 0
  123.     local isPlntbl = true
  124.     while isPlntbl and indx < 16 do
  125.       indx = indx + 1
  126.       turtle.select(indx)
  127.       isPlntbl=turtle.getItemCount()>0
  128.     end
  129.     plntblCnt = indx - 1
  130.   end
  131.   return plntblCnt
  132. end
  133.  
  134.  
  135. frm.consolidate = function()
  136.   local lowestToMove=initPlntblCnt()+1
  137.   local sltToMove = 16
  138.   local isMoving = true
  139.   local trnsfrs =  0
  140.   while isMoving do
  141.    
  142.     local isChecking =
  143.         turtle.getItemCount(
  144.             sltToMove ) > 0
  145.     local chckSlt = 1
  146.     while isChecking do
  147.       turtle.select(sltToMove)
  148.       if turtle.transferTo(
  149.           chckSlt ) then
  150.         trnsfrs= trnsfrs+ 1
  151.         if turtle.getItemCount(
  152.             sltToMove) <= 0 or
  153.             chckSlt+1>= sltToMove then
  154.           isChecking = false
  155.         end
  156.       end
  157.       chckSlt= chckSlt + 1
  158.     end
  159.     sltToMove = sltToMove - 1
  160.     isMoving=sltToMove>=lowestToMove
  161.   end
  162.   print( "invntry cnsldtion trnsfrs: ",
  163.       trnsfrs )
  164. end
  165.  
  166. -- For the non - reference slots,
  167. -- find one that matches the
  168. -- currently selected and match that.
  169. -- Or return false.
  170. local function selectNonRefSlot()
  171.  
  172.   local s = plntblCnt + 1
  173.   local seedy = false
  174.   while s < 16 and seedy == false do
  175.     seedy = turtle.compareTo( s )
  176.     if seedy then
  177.       turtle.select(s)
  178.     end
  179.     s = s + 1
  180.   end --while
  181.   return seedy
  182. end
  183.  
  184. -- Decides what to plant based on the
  185. --  reference slots (plntblCnt).
  186. -- @param rowIndex the current row
  187. -- @block block # within the row,
  188. --  starting with 0, closest to start
  189. -- @param prevRow an array of crop
  190. --  types for previous row
  191. local function sow( rowIndex, block,
  192.     prevRow )
  193.   local seedy = true
  194.  
  195.   -- Alternate among the plantables:
  196.   -- loop through reference slots.
  197.   local i = 0
  198.   local refSlt = 0
  199.   local isPlanted = false
  200.   local isAvailable = false
  201.   local isAppropriate = false
  202.   local unavailCount = 0
  203.   while i < plntblCnt and not isPlanted do
  204.     --use what was for a given reference slot
  205.     refSlt = ( (rowIndex + i )% plntblCnt) + 1
  206.    
  207.     turtle.select(refSlt)
  208.     -- leave in each reference slot
  209.     if turtle.getItemCount(refSlt) >
  210.         MIN_REF then
  211.       isAvailable = true
  212.     else
  213.       isAvailable = selectNonRefSlot()
  214.     end
  215.    
  216.     isAppropriate =
  217.         not( prevRow[block]== refSlt )
  218.    
  219.     if isAvailable and isAppropriate then
  220.       prevRow[block] = refSlt
  221.       turtle.placeDown()
  222.       isPlanted = true
  223.     else
  224.       if not isAvailable then
  225.         unavailCount= unavailCount + 1
  226.       end
  227.     end
  228.    
  229.     i = i + 1
  230.   end
  231.  
  232.   if not isPlanted then
  233.     prevRow[block] = 0
  234.     if unavailCount >= plntblCnt then
  235.       seedy = false
  236.       print("Apparently, out of seeds")
  237.     end
  238.   end
  239.  
  240.   return seedy
  241. end
  242.  
  243. -- Harvests a row: Digs (hoes) and
  244. -- moves forward the length or until
  245. -- the way is blocked
  246. -- @param lth the expected length of
  247. --  the row or 0 if not yet determined
  248. -- @param firstRow
  249. -- @param prevRow - array of seed types
  250. --  represented by ref slots
  251. -- @param rowIdx the row index
  252. -- @return how long the row was, or
  253. --  0 if there was an unexpected stop
  254. --  due to fuel outage after first row.
  255. --  Also returns isSeedy, that is, are
  256. --  there still enough seeds to use.
  257. local function sowAndReapRow( lth,
  258.     firstRow, prevRow, rowIdx )
  259.   -- print( "Reaping a row ")
  260.  
  261. -- Loop until length is reached or
  262. -- the way is blocked
  263.   local keepGoing = true
  264.   local placeR = 1
  265.  
  266.   if firstRow then
  267.     local fuel = turtle.getFuelLevel()
  268.    
  269.     local maxLth = 0
  270.     if fuel == "unlimited" then
  271.       maxLth = DEFAULT_MAX_LENGTH
  272.     else
  273.       maxLth = fuel/2 - 1
  274.     end
  275.    
  276.     if lth > maxLth then
  277.       lth = maxLth
  278.      
  279.       print("First row. "
  280.           .."fuel, max length: ",
  281.           fuel, lth)
  282.     end
  283.   end
  284.  
  285.   local isSeedy = true
  286.   while keepGoing do
  287.    
  288.     turtle.digDown() -- reaps
  289.    
  290.     if firstRow then
  291.       prevRow[placeR - 1] = 0
  292.     end
  293.    
  294.     local placeIdx = placeR-1
  295.     local block = 0
  296.     if rowIdx % 2 == 0 then  --Even
  297.       block = placeIdx
  298.     else
  299.       block = (lth-1) - placeIdx
  300.     end
  301.    
  302.     isSeedy = sow(rowIdx, block,
  303.         prevRow )
  304.  
  305.     -- sees if it can keepGoing
  306.     if keepGoing then
  307.       placeR = placeR + 1
  308.       if placeR > lth and lth > 0 then
  309.         keepGoing = false
  310.       else
  311.         keepGoing = turtle.forward()
  312.       end
  313.       -- prevents infinite loop
  314.       if placeR > 1023 then
  315.         keepGoing = false
  316.       end
  317.     else
  318.       if firstRow == false then
  319.         print("Stopped unexpectedly")
  320.         placeR = 0
  321.         print("placeR="..placeR)
  322.       end
  323.     end
  324.    
  325.   end -- while loop
  326.  
  327.   lth = placeR - 1
  328.   return lth, isSeedy
  329. end
  330.  
  331. -- Determines whether there's enough
  332. -- fuel to: move to another row,
  333. -- reap it, sow it, and return to
  334. -- base
  335. -- @param rowIndex, rowLength
  336. local function isFuelOKForNextRow(
  337.     rowIndex, rowLength)
  338.  
  339.   local fuelNeed = rowIndex+ rowLength
  340.  
  341.   local fuelLevel = turtle.getFuelLevel()
  342.  
  343.   local isEnough = false
  344.   if fuelLevel == "unlimited" then
  345.     isEnough = true
  346.   else
  347.     isEnough= fuelLevel >= fuelNeed
  348.   end
  349.  
  350.   if isEnough ~= true then
  351.     print("Not enough fuel for next "
  352.         .."row and return trip.")
  353.     print( string.format(
  354.         "fuelNeed %d, rowIndex %d, "
  355.         .."rowLength %d", fuelNeed,
  356.         rowIndex, rowLength ) )
  357.        
  358.     print( "fuelLevel: ", fuelLevel )
  359.    
  360.   end
  361.  
  362.   return isEnough
  363.  
  364. end
  365.  
  366. --[[ Turns and moves to the next row
  367.      @param rowIndex
  368.      @param isFuelOK
  369.      @returns isBlocked ]]
  370. local function moveToNext(rowIndex,
  371.     isFuelOK )
  372.  
  373.   local isEven= rowIndex % 2== 0
  374.    
  375.   print( string.format(
  376.           "moveToNext( isEven %s, "
  377.           .."isFuelOK %s )",
  378.           tostring( isEven ),
  379.           tostring( isFuelOK ) ) )
  380.  
  381.   local isBlocked = false
  382.  
  383.   if isFuelOK then
  384.     -- Move to the next row
  385.     if isEven then
  386.       turtle.turnRight()
  387.      
  388.       isBlocked=turtle.forward()==false
  389.  
  390.         turtle.turnRight()
  391.      
  392.     else -- is odd
  393.       turtle.turnLeft()
  394.      
  395.       isBlocked=turtle.forward()==false
  396.  
  397.         turtle.turnLeft()
  398.      
  399.     end -- even vs odd
  400.   end -- isFuelOK
  401.  
  402.   print( string.format(
  403.       "moveToNext(): isBlocked= %s",
  404.       tostring( isBlocked )) )
  405.  
  406.   return isBlocked
  407.  
  408. end
  409.  
  410. -- Checks fuel, and if good, moves to
  411. --    next row, reaps and sows.
  412. -- @param rowLength, isFirst, prevRow,
  413. --    rowIndex.
  414. --    prevRow is array of ints, each
  415. --    a reference item slot, from, you
  416. --    guessed it: the previous row.
  417. -- @return isFuelOK, rowLength, isSeedy,
  418. --    isBlocked.  isSeedy means there
  419. --    are still seeds to be planted.
  420. --    isBlocked means it was blocked
  421. --    when moving from one row to the
  422. --    next, which is meant to be a
  423. --    normal scene.
  424. local function doOneAndMoveOn( rowLength,
  425.     isFirst, prevRow, rowIndex )
  426.  
  427.   local isFuelOK = true
  428.   local isSeedy = true
  429.   local isBlocked = false
  430.  
  431.   isFuelOK = isFuelOKForNextRow(
  432.       rowIndex, rowLength )
  433.  
  434.   if isFuelOK and isSeedy and
  435.       not isBlocked then
  436.    
  437.     rowLength, isSeedy= sowAndReapRow(
  438.         rowLength, isFirst, prevRow,
  439.         rowIndex )
  440.  
  441.   end -- if fuel OK
  442.  
  443.   isBlocked = moveToNext( rowIndex,
  444.       isFuelOK )
  445.  
  446.   return isFuelOK, rowLength, isSeedy,
  447.       isBlocked
  448.  
  449. end
  450.  
  451. -- Harvests and plants the rows
  452. -- @param rowLength
  453. -- @param rows number of expected
  454. --    plantable rows.  If 0, then
  455. --    it's reset to rowLength.
  456. -- @return number of rows planted.
  457. --  If stopped unexpectedly this will
  458. --  be 0.
  459. -- Also returns row length, & isBlocked
  460. local function reapAndSow( rowLength,
  461.     rows )
  462.   -- print("beginning reapAndSow()")
  463.   -- Find out how many slots are for
  464.   -- reference.
  465.   local plntbl = initPlntblCnt()
  466.  
  467.   print("The first "..plntbl..
  468.     " slots \nare deemed plantable")
  469.  
  470.   turtle.up()
  471.  
  472.   local prevRow = {}
  473.   if rows == 0 then
  474.     rows = rowLength
  475.   end
  476.   print("rows = ".. rows)
  477.   local rowIndex = 0
  478.   local isSeedy = true
  479.   local isFuelOK = true
  480.   local isFirst = true
  481.   local isBlocked = false
  482.  
  483.   while (rowIndex< rows) and isSeedy
  484.       and isFuelOK and not isBlocked do
  485.    
  486.     print( "rowIndex ".. rowIndex )
  487.    
  488.     -- If there was an unexpected
  489.     -- stop in previous row, then
  490.     -- rowLength will be its initial
  491.     -- value, 0
  492.     if rowLength<= 0 and
  493.         isFirst== false then  
  494.       -- Stops loop
  495.       isSeedy = false
  496.     else
  497.      
  498.       isFuelOK, rowLength, isSeedy,
  499.           isBlocked =
  500.           doOneAndMoveOn( rowLength,
  501.           isFirst, prevRow, rowIndex )
  502.      
  503.       if plntblCnt >
  504.           CONSOLIDATE_THRESHOLD and
  505.           rowIndex %
  506.           CONSOLIDATE_FREQCY == 0 then
  507.         frm.consolidate()
  508.       end
  509.      
  510.      
  511.       -- for troubleshooting
  512.       print( string.format(
  513.           "in farm(), after "
  514.           .."doOneAndMoveOn( rowLength %d, "
  515.           .."isFirst %s, rowIndex %d)",
  516.           rowLength, tostring(isFirst),
  517.           rowIndex ) )
  518.      
  519.       print( string.format(
  520.           "Which returned isFuelOK %s, "
  521.           .."rowLength %d, isSeedy %s"
  522.           ..", isBlocked %s",
  523.           tostring( isFuelOK ), rowLength,
  524.           tostring(isSeedy),
  525.           tostring(isBlocked) ) )
  526.      
  527.       print("_____")
  528.       -- os.sleep(5)
  529.      
  530.     end -- if rowLength > 0 & not first
  531.    
  532.     isFirst = false
  533.     rowIndex = rowIndex + 1
  534.    
  535.   end -- while rows & isSeedy
  536.  
  537.   -- The number of rows traversed
  538.   -- or 0 if unexpected problem
  539.   local rowsDone = 0
  540.   if rowLength > 0 then
  541.  
  542.     -- If fuel was too low, it did not
  543.     -- move to next row, so therefore
  544.     -- its row is one less than otherwise
  545.     if isFuelOK then
  546.       rowsDone = rowIndex
  547.     else
  548.       rowsDone = rowIndex - 1
  549.     end
  550.   else
  551.     rowsDone = 0
  552.   end
  553.  
  554.   return rowsDone, rowLength, isBlocked
  555.  
  556. end
  557.  
  558. -- Returns to the start and drops all
  559. -- inventory except one of each
  560. -- reference item. (It's assumed there
  561. -- are hoppers & a chest.)
  562. -- @param rows how many rows are
  563. --  planted.
  564. -- @param length in case we're at the
  565. --  other end of a row, how many
  566. -- @param isBlocked indicates that
  567. --  we could *not* move to next row.
  568. -- @return true if successful. False
  569. --  means there was blockage or fuel
  570. --  outage.
  571. local function returnAndStore( rows,
  572.     length, isBlocked )
  573.  
  574.   local canGo = true
  575.   local steps = rows
  576.   if isBlocked then
  577.     steps = rows - 1
  578.   end
  579.  
  580.   print( string.format(
  581.         "returnAndStore(): rows %d,"
  582.         .. " steps %d, length %d, "
  583.         .. "isBlocked %s",
  584.         rows, steps, length,
  585.         tostring(isBlocked) ))
  586.  
  587.   -- If rows is odd, turtle is at
  588.   -- opposite end so it must return
  589.   if rows % 2 == 1 then   -- odd
  590.     for i = 1, length - 1 do
  591.       turtle.forward()
  592.     end
  593.     turtle.turnRight()
  594.   else
  595.     turtle.turnLeft()
  596.   end
  597.  
  598.   local stp = 1
  599.   while (stp <= steps) and canGo do
  600.     canGo = turtle.forward()
  601.     stp = stp + 1
  602.   end
  603.  
  604.   turtle.turnLeft()
  605.   turtle.digDown()
  606.   turtle.down()
  607.  
  608.   if canGo then
  609.     for i = 16, 1, -1 do
  610.       turtle.select(i)
  611.       if i > plntblCnt then
  612.         turtle.drop()
  613.       else
  614.         -- In reference slots, leave
  615.         -- at least 2 so that the first
  616.         -- can be planted.
  617.         turtle.drop(
  618.             turtle.getItemCount(i)- MIN_REF)
  619.       end
  620.     end
  621.   else
  622.     print("couldn't store")
  623.   end --canGo
  624.   turtle.turnLeft()
  625.   turtle.turnLeft()
  626.   return canGo
  627. end
  628.  
  629. -- This prints a message about the fuel
  630. -- situation.
  631. -- @param n is how many plantings have
  632. --  been completed so far
  633. -- @param fuelStart
  634. -- @param widthFromUsr is how wide the
  635. --  farm should have been according to
  636. --  the user.
  637. local function printFuelMsg(n, fuelStart,
  638.     widthFromUsr)
  639.  
  640.   local fuelLevel = turtle.getFuelLevel()
  641.  
  642.   print("after harvest: "..(n)
  643.     .." of ".. MAX_REPEATS)
  644.    
  645.   print("fuelLevel ".. fuelLevel)
  646.   local fuelPerTurn = 0
  647.   if fuelLevel == "unlimited" then
  648.     fuelLevel = DEFAULT_FUEL
  649.     fuelPerTurn = 1
  650.   else
  651.     fuelPerTurn = (fuelStart-fuelLevel)  
  652.   end
  653.  
  654.   print( "fuelPerTurn ".. fuelPerTurn )
  655.  
  656.   local fltTurns = fuelLevel/fuelPerTurn
  657.   local floorTrns = math.floor( fltTurns )
  658.   local frction = fltTurns - floorTrns
  659.   local rowsPart = frction * widthFromUsr
  660.  
  661.   print( string.format(
  662.       "There would be enough fuel "
  663.       .."for %d more turns "
  664.       .."plus %d rows.",
  665.       floorTrns, rowsPart ))
  666.      
  667.   if fuelLevel< fuelPerTurn and n < MAX_REPEATS then
  668.     local fuelNeeded = (1 - frction) * fuelPerTurn
  669.     local coals = math.ceil(fuelNeeded/80);
  670.    
  671.     print( string.format(
  672.         "To finish the next harvest "
  673.         .."as well or better than this one, "
  674.         .."%d more fuel units are "
  675.         .."needed.  That's %d pieces "
  676.         .."of coal at least.  "
  677.         .."Slot #9 please", fuelNeeded,
  678.         coals ) )
  679.        
  680.   end
  681.  
  682. end
  683.  
  684. -- Farms the field repeatedly up to
  685. -- MAX_REPEATS, or the fuel runs out,
  686. -- or there's some unexpected stop.
  687. -- @param widthFromUsr is the width
  688. --  of the square farm, according to
  689. --  user.  If 0, this will estimate
  690. --  the maximum width according to
  691. --  fuel.
  692. -- @param rows for non-square field
  693. local function farm( widthFromUsr, rows )
  694.  
  695.     --[[ Start ]]
  696.     -- three times, if enough fuel
  697.     local n = 1
  698.     local okSoFar = true
  699.     while n<= MAX_REPEATS and okSoFar do
  700.       local startTime = os.clock();
  701.       turtle.select(9)
  702.       turtle.refuel()
  703.       local fuelStart = turtle.getFuelLevel()
  704.       print("fuel at start = ".. fuelStart)
  705.      
  706.       if fuelStart == "unlimited" then
  707.         fuelStart = DEFAULT_FUEL
  708.       end
  709.      
  710.       local maxLnth = math.floor(
  711.           math.sqrt(fuelStart+ 1)- 1)
  712.      
  713.       print("Estimated max field "
  714.           .. "side \nfor full cycle: "
  715.           .. maxLnth)
  716.      
  717.       if widthFromUsr == 0 then
  718.         widthFromUsr = maxLnth
  719.       end
  720.      
  721.       local rowsDone, lngth, isBlocked =
  722.           reapAndSow( widthFromUsr, rows )
  723.      
  724.       okSoFar = returnAndStore(
  725.           rowsDone, lngth, isBlocked )
  726.  
  727.       if rowsDone > 0 then
  728.         if okSoFar then
  729.        
  730.           printFuelMsg(n, fuelStart, widthFromUsr )
  731.          
  732.           local endTime = os.clock()
  733.           local duration = endTime - startTime
  734.           local waitTime = ( GROW_WAIT*60)-duration
  735.           local nextTime = endTime+ waitTime
  736.           if (n < MAX_REPEATS) and okSoFar then
  737.             if not isMockUp then
  738.               os.sleep(waitTime)
  739.             end
  740.           end
  741.         end --okSofar
  742.       else
  743.         okSoFar = false
  744.       end
  745.       n = n + 1
  746.     end -- of MAX_REPEATS loop
  747.    
  748.     if okSoFar == false then
  749.       print("Stopped.")
  750.     end
  751.  
  752. end
  753.  
  754. local function main( tArgs )
  755.   local widthFromUsr = 0
  756.   local rowsFromUsr = 0
  757.   --[[ If user supplies a good number,
  758.   this uses it as row count.  If user
  759.   supplied a bad argument, it indicates.
  760.   ]]
  761.   local argCount = table.getn(tArgs)
  762.   local badArg = false
  763.   local badArgMsg = "Argument OK"
  764.   if argCount > 0 then
  765.     widthFromUsr = tArgs[1]
  766.     if tonumber(widthFromUsr)==nil then
  767.       badArg = true
  768.       badArgMsg = "Arg 1 not a number"
  769.     else
  770.       widthFromUsr = tonumber(widthFromUsr)
  771.     end
  772.    
  773.    -- and use it
  774.   if argCount > 1 then
  775.     rowsFromUsr = tArgs[2]
  776.     if tonumber(rowsFromUsr)==nil then
  777.       badArgMsg = badArgMsg..
  778.           "... Arg 2 not a number"
  779.     else
  780.       rowsFromUsr= tonumber(rowsFromUsr)
  781.     end  
  782.    
  783.   end -- multpl args
  784.    
  785.   else -- There were no arguments
  786.     badArg = true
  787.     badArgMsg =
  788. "Supply width and length of farm as \n"
  789. .."params or 0 to use blockage instead."
  790.  
  791.   end -- argCount
  792.    
  793.   if badArg then
  794.     print( badArgMsg )
  795.     print("Put at least ".. MIN_REF..
  796.         " of something")
  797.  
  798.     print(
  799. "plantable in each of the first few \n"
  800. .. "slots (top row)")
  801.  
  802.     print(
  803.      "Fuel goes to slot #9. (3rd row ")
  804.    
  805.     print(" down, leftmost)")
  806.  
  807.   else
  808.     farm( widthFromUsr, rowsFromUsr )
  809.   end
  810.  
  811. end
  812.  
  813. local tArgs = {...}
  814.  
  815. -- TODO for TEST comment-out main()
  816. main(tArgs)
  817.  
  818. return frm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement