Advertisement
dadragon84

tLoader

Feb 18th, 2025
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --{program="tLoader",version="1.10",date="2024-10-22"}
  2. ---------------------------------------
  3. -- tLoader            by Kaikaku
  4. -- 2024-10-22, v1.10   UI fix
  5. -- 2021-04-02, v1.01  tClear added
  6. -- 2021-03-20, v1.00  initial
  7. -- TUAPv1FU (tLoader)
  8. ---------------------------------------
  9.  
  10. ---------------------------------------
  11. ---- DESCRIPTION ----------------------
  12. ---------------------------------------
  13. -- Loader program to pastebin get
  14. --   all the other releazed programs.
  15. -- If in-program info is insufficient
  16. --   check out YouTube for more details.
  17.  
  18.  
  19. ---------------------------------------
  20. ---- ASSUMPTIONS ----------------------
  21. ---------------------------------------
  22. -- Atm mainly meant for turtles
  23. --
  24.  
  25.  
  26. ---------------------------------------
  27. ---- VARIABLES: template --------------
  28. ---------------------------------------
  29. local cVersion  ="v1.10"              
  30. local cPrgName  ="tLoader"          
  31. local cMinFuel  =110                  
  32. local cSleepTime=0.4                
  33. local cMaxTurns =-1                  
  34. local turnCounter =0                  
  35. local turnsRemaining =cMaxTurns      
  36. local harvestedStuff=0                
  37. local harvestedStuffTotal=0          
  38.  
  39. local blnAskForParameters =true      
  40. local blnShowUsage        =false    
  41. local blnDebugPrint       =false
  42. local blnTurtle                      
  43. local isComputer          =false      
  44. local baseColor=colors.blue          
  45.  
  46.  
  47. ---------------------------------------
  48. ---- VARIABLES: specific --------------
  49. ---------------------------------------
  50. local blnAll  = false
  51. local blnAllA = false
  52. local blnAllT = false
  53. local blnAllB = false
  54. local blnDelete = false
  55. local singleProg1 = ""
  56. local singleProg2 = ""
  57. local singleProg3 = ""
  58. local counter = 0
  59.  
  60. ---------------------------------------
  61. ---- Data: specific -------------------
  62. ---------------------------------------
  63.  
  64. --     id, name, pastebin, applicability[t/c/b]
  65. local array={}
  66. array={
  67.        "a","AESeeds",        "stXEtJ6C","t",
  68.        "a","CabReactor",     "knYniUQx","t",
  69.        "a","EndoFeeder",     "bMHsGY06","t",
  70.        "a","FlowerPot",      "EiBtxqUT","t",
  71.        "a","Harvester",      "ZVc6H649","t",
  72.        "a","MilkPower",      "e8bs7VnN","t",
  73.        "a","TreeFarm",       "Qn008fPa","t",
  74.        
  75.        "b","9x9",            "a5nWDnK6","t",
  76.        "b","Dome",           "jEAYUJdZ","t",
  77.        "b","DonkeySanctuary","Xc98RnqU","t",
  78.        "b","Door2x3",        "BvavMNTW","t",
  79.        "b","Drone",          "A35d84ge","b",
  80.        "b","Chandelier",     "bMky9MzP","t",
  81.        "b","HalfTimberHouse","hxeZ5Wui","t",
  82.        "b","Head",           "HP3AW3sd","t",
  83.        "b","Mansion",        "PfdurUkb","t",
  84.        "b","MobFarm",        "unPPhDpQ","t",
  85.        "b","Shuttle",        "L1UQ3he3","t",
  86.        "b","TownHouse",      "FHw76UHP","t",
  87.        
  88.        "t","Clear",          "07653J4E","t",
  89.        "t","Fireworks",      "UYm0CCQ7","t",
  90.        "t","Loader",         "TUAPv1FU","b",
  91.        "t","Platform",       "fbyxVzSX","t",
  92.        "t","Send",           "h3xcC9S1","b",
  93.        "t","WaitFor",        "9vzPCd4T","b"}
  94.  
  95. ---------------------------------------
  96. ---- Early UI functions ---------------
  97. ---------------------------------------
  98. local function swapColors()
  99. local backColor=term.getBackgroundColor()
  100. local textColor=term.getTextColor()
  101.  
  102. term.setBackgroundColor(textColor)
  103. term.setTextColor(backColor)
  104. end
  105.  
  106. local function printUI(strInput)
  107. if strInput==ni then strInput="" end
  108.  
  109.   if strInput=="header" then  
  110.     term.write("+-------------------------------------") print("+")  
  111.   elseif strInput=="line" then
  112.     term.write("+-------------------------------------") print("+")
  113.   elseif strInput=="footer" then
  114.     term.write("+-------------------------------------") print("+")
  115.   else
  116.     term.write("|")
  117.     strInput=strInput.."                                     "
  118.     term.write(string.sub(strInput,1,37))
  119.     print("|")
  120.   end
  121. end
  122.  
  123. local function coloredTextAt(inputText,outputRow,outputCol,textColor,backColor)
  124. -- writes and colors text to coordinates
  125. local oldRow, oldCol = term.getCursorPos()
  126. local oldTextColor=term.getTextColor()
  127. local oldBackColor=term.getBackgroundColor()
  128. if textColor==nil then textColor=term.getTextColor() end
  129. if backColor==nil then backColor=term.getBackgroundColor() end
  130.  
  131.   term.setTextColor(textColor)
  132.   term.setBackgroundColor(backColor)
  133.   term.setCursorPos(outputRow,outputCol)
  134.   term.write(inputText)
  135.   term.setCursorPos(oldRow, oldCol)
  136.   term.setTextColor(oldTextColor)
  137.   term.setBackgroundColor(oldBackColor)
  138. end
  139.  
  140. ---------------------------------------
  141. ---- tArgs ----------------------------
  142. ---------------------------------------
  143. local tArgs = {...}  
  144. term.clear() term.setCursorPos(1,1)
  145.  
  146. -- header
  147. if #tArgs~=0 then
  148.   blnAskForParameters=false
  149.   term.clear() term.setCursorPos(1,1)
  150.   printUI("header")
  151.   printUI(""..cPrgName..", "..cVersion..", by Kaikaku. Enjoy!")
  152.   printUI("line")
  153.   coloredTextAt(cPrgName,2,2,baseColor)
  154.   print("Starting...")
  155. end
  156.  
  157. for t=1,#tArgs do
  158.   if string.lower(tArgs[t])=="all" then
  159.     blnAll=true
  160.   elseif string.lower(tArgs[t])=="a" then
  161.     blnAllA=true
  162.   elseif string.lower(tArgs[t])=="t" then
  163.     blnAllT=true
  164.   elseif string.lower(tArgs[t])=="b" then
  165.     blnAllB=true
  166.   elseif string.lower(tArgs[t])=="del" then
  167.     blnDelete=true
  168.   elseif string.lower(tArgs[t])=="delte" then
  169.     blnDelete=true
  170.   elseif singleProg1=="" then
  171.     singleProg1 = tArgs[t]
  172.   elseif singleProg2=="" then
  173.     singleProg2 = tArgs[t]
  174.   else
  175.     singleProg3 = tArgs[t]
  176.   end
  177. end
  178.  
  179.  
  180. ---------------------------------------
  181. -- basic functions for turtle control -
  182. ---------------------------------------
  183.  
  184. local function spd(s,blnForward)
  185.   if s==nil then s=turtle.currentSlot() end
  186.   if blnForward==nil then blnForward=true end
  187.   ss(s) pd() if blnForward then gf() end
  188. end
  189. local function spu(s,blnForward)
  190.   if s==nil then s=turtle.currentSlot() end
  191.   if blnForward==nil then blnForward=true end
  192.   ss(s) pu() if blnForward then gf() end
  193. end
  194. local function spf(s,blnBack)
  195.   if s==nil then s=turtle.currentSlot() end
  196.   if blnBack==nil then blnBack=true end
  197.   ss(s) pf() if blnBack then gb() end
  198. end
  199.  
  200. local function waitKey(strText)
  201.   local event, scancode
  202.   write(strText)
  203.   event, scancode = os.pullEvent("key")
  204.   print()
  205. end
  206.  
  207. local function askForInputText(textt)
  208.   local at=""
  209.   -- check prompting texts
  210.   if textt==nil then textt="Enter text:" end
  211.  
  212.   -- ask for input
  213.   write(textt)
  214.   at=read()
  215.   return at
  216. end
  217.  
  218. local function askForNumber(askText, minValue, maxValue)
  219. -- gets entered data, ensures it's a number and returns it
  220. -- keeps asking if entry is not a number
  221. -- adapts to min and max values
  222. -- allways writes in screen line 13 (last for turtles)
  223. -- calls askForInputText
  224. local blnReask=true
  225. local returnNumber=nil
  226. if minValue==nil then minValur=1 end
  227. if maxValue==nil then maxValue=100 end
  228. if askText==nil then askText="Key in number and press Enter: " end
  229.   while blnReask do
  230.    term.setCursorPos(1,13)
  231.     returnNumber=askForInputText(askText)
  232.     if returnNumber==nil then
  233.       blnReask=true
  234.     else  
  235.       returnNumber=tonumber(returnNumber)
  236.       if returnNumber==nil then
  237.         blnReask=true
  238.       else
  239.         returnNumber=math.floor(returnNumber)
  240.         if returnNumber>maxValue then returnNumber=maxValue end
  241.         if returnNumber<minValue then returnNumber=minValue end
  242.         blnReask=false
  243.       end
  244.     end
  245.   end
  246.   return returnNumber
  247. end
  248.  
  249. local function pressKeyNoSpecials(askText)
  250. -- excludes ctrl / alt / shifts
  251. -- catches windows
  252. -- retruns the key number (if needed at all)
  253. local tmpEvent, tmpKey
  254. if askText==nil then askText="Press key to START! (stop w/ ctrl+t)   " end
  255.   tmpKey=341
  256.   while tmpKey>=340 and tmpKey<=346 do -- ctrls, alts, shifts
  257.     term.write(askText) tmpEvent, tmpKey = os.pullEvent("key")
  258.     if tmpKey==nil then tmpKey=341 end -- win
  259.   end
  260.   return tmpKey
  261. end
  262.  
  263. local function checkFuel()
  264.   local tmp=turtle.getFuelLevel()
  265.   return tmp
  266. end
  267.  
  268. local function checkTurtle(blnOnlyIdentify)
  269. if blnOnlyIdentify==nil then blnOnlyIdentify=false end
  270. -- turtle?
  271.   local turtleOk, turtleVal = pcall(checkFuel)
  272.   if not turtleOk then
  273.     blnTurtle=false
  274.     if not blnOnlyIdentify then
  275.       term.clear() term.setCursorPos(1,1)
  276.       printUI("header")
  277.       printUI(""..cPrgName..", "..cVersion..", by Kaikaku ("..iPage.."/"..iPageMax..")")
  278.       printUI("line")
  279.       printUI("This is a turtle program.")
  280.       printUI("  Please, execute it with a turtle!")
  281.       printUI("footer")
  282.    
  283.       coloredTextAt(cPrgName,2,2,colors.red)
  284.       error()
  285.     end
  286.   else
  287.     blnTurtle=true
  288.   end
  289. end
  290.  
  291. local function sleepDots(sec, duration)
  292. if sec==nil then sec=10 end
  293. if sec<1 then return end
  294. if duration==nil then duration=1 end -- shorten durtation for more dots
  295.  
  296.   for i=1,sec-1 do
  297.     sleep(1*duration)
  298.     term.write(".")
  299.   end
  300.  
  301.   sleep(1)
  302.   print(".")
  303. end
  304.  
  305. local function debugPrint(str)
  306.  if blnDebugPrint then print(str) end
  307. end
  308.  
  309. local function inspectFor(blockArray, strDirection)
  310. if strDirection==nil then strDirection="f" end
  311. local blnOk, data
  312.  
  313.   -- inspect
  314.   if strDirection=="d" then blnOk, data = turtle.inspectDown()
  315.   elseif strDirection=="u" then blnOk, data = turtle.inspectUp()
  316.   elseif strDirection=="f" then blnOk, data = turtle.inspect()
  317.   else
  318.     print("Warning: Unknown direction '",strDirection,"' in inspectFor, taking (f)orward instead.")
  319.     strDirection="f"
  320.     blnOk, data = turtle.inspect()
  321.   end
  322.   if data.name~=nil then debugPrint("Found:"..string.lower(data.name)) end
  323.   -- compare
  324.   local i=1
  325.   while blockArray[i]~=nil do
  326.   debugPrint("Compare to:"..string.lower(blockArray[i]))
  327.     if data.name~=nil then
  328.       if string.lower(data.name) == string.lower(blockArray[i]) then return true end
  329.     end
  330.     i=i+1
  331.   end
  332.  
  333.   return false -- reached a nil value
  334. end
  335.  
  336. local function handleReport()
  337.   print("  Harvested items this turn: "..harvestedStuff)
  338.   harvestedStuffTotal=harvestedStuffTotal+harvestedStuff
  339.   harvestedStuff=0
  340.   print("  Harvested items total: "..harvestedStuffTotal)
  341. end
  342.  
  343. local function handleTurnCounter()
  344. -- return true if cMaxTurns is reached, else false
  345.   handleReport()
  346.   if turnsRemaining==0 then return true end
  347.   turnCounter=turnCounter+1
  348.   if cMaxTurns>=0 then
  349.     turnsRemaining=turnsRemaining-1
  350.     term.write("Turn "..turnCounter.."/"..cMaxTurns..":")
  351.   else
  352.     term.write("Turn "..turnCounter..":")
  353.   end
  354.   return false
  355. end
  356.  
  357.  
  358. local function getFirstEmptySlot(startAt)
  359. if startAt==nil then startAt=1 end
  360. if startAt>16 or startAt<1 then return nil end
  361.  
  362.   for i=startAt,16,1 do
  363.     if gic(i)==0 then return i end  
  364.   end
  365.   for i=1,startAt,1 do
  366.     if gic(i)==0 then return i end  
  367.   end
  368.   return nil
  369. end
  370.  
  371. local function identifyTool(toolSide)  
  372. -- returns name of tool at side toolSide
  373. -- returns no_tool if there is none
  374. -- requires at least one empty slot for tool check (throws error)
  375. if toolSide==nil then toolSide="right" end
  376. if toolSide~="right" and toolSide~="r" then toolSide="left" end
  377. local slotNumber = getFirstEmptySlot()
  378. local slotSelected=turtle.getSelectedSlot()
  379. local toolName="no_tool"
  380.  
  381.   if slotNumber==nil then error("Couldn't find empty slot to check tool on side '"..toolSide.."'!") end
  382.   ss(slotNumber)
  383.   -- step 1: get name
  384.   if toolSide=="right" or toolSide=="r" then
  385.     turtle.equipRight()
  386.   else
  387.     turtle.equipLeft()  
  388.   end
  389.   -- step 2: get name
  390.   local data = turtle.getItemDetail()
  391.   if data~=nil then toolName=data.name end
  392.   -- step 3: re-equipget name
  393.   if toolSide=="right" or toolSide=="r" then
  394.     turtle.equipRight()
  395.   else
  396.     turtle.equipLeft()  
  397.   end
  398.   ss(slotSelected)
  399.   return toolName
  400. end
  401.  
  402.  
  403. -- pre description ------------------------
  404. local function arrangeArray(inputArray, startAt, endAt, widthAt, maxRows, maxCharacters, numSpacers)
  405. -- prints array in two columns
  406. if widthAt==nil then widthAt=4 end  -- how many array itmes belong to one "object"
  407. if widthAt<1 then widthAt=4 end
  408. if startAt==nil then startAt=1 end  -- start with this "object"
  409. if startAt<1 then startAt=1 end
  410. if endAt==nil then endAt=#inputArray/widthAt end -- end at this "object"
  411. if endAt>#inputArray*widthAt then endAt=#inputArray/widthAt end
  412. if maxRows==nil then maxRows=10 end  -- so many rows to display
  413. if maxRows<1 then maxRows=5 end
  414. if maxCharacters==nil then maxCharacters=19 end  -- so many chars in one column (rest is cut off)
  415. if maxCharacters<1 then maxCharacters=19 end
  416. local fillerA=" "--"-"
  417. if numSpacers==nil then numSpacers=0 end  -- so many spaces between both columns
  418. if numSpacers<1 then numSpacers=0 end
  419. local fillerB=" "--"x"
  420.  
  421. local outputArray={}
  422. local j=1
  423. local tmpString=""
  424. local tmpSpaces=""
  425. local tmpSpacer=""
  426.  
  427.   for i=1,maxCharacters,1 do
  428.     tmpSpaces=tmpSpaces..fillerA
  429.   end
  430.   for i=1,numSpacers,1 do
  431.     tmpSpacer=tmpSpacer..fillerB
  432.   end
  433.  
  434.   for i=startAt*widthAt-(widthAt-1),endAt*widthAt,widthAt do
  435.      
  436.       --print(inputArray[i]..inputArray[i+1])
  437.       tmpString=inputArray[i]..inputArray[i+1]..tmpSpaces
  438.       tmpString=string.sub(tmpString,1,maxCharacters)
  439.       if outputArray[j]==nil then outputArray[j]="" tmpString=tmpString..tmpSpacer end
  440.       outputArray[j]=outputArray[j]..tmpString
  441.       j=j+1
  442.       if j>maxRows then j=1 end
  443.   end
  444.  
  445.   return outputArray
  446. end
  447.  
  448. local function printArray(iArray)
  449.   for i=1,#iArray,1 do
  450.     term.write(i)
  451.     if iArray[i]~=nil then print(iArray[i]) else print() end
  452.   end
  453.  
  454. end
  455.  
  456. local function countProgramTypes()
  457. local countA=0
  458. local countB=0
  459. local countT=0
  460.  
  461.   for i=1,#array,4 do
  462.     if array[i]=="a" then
  463.       countA=countA+1
  464.     elseif array[i]=="b" then
  465.       countB=countB+1
  466.     elseif array[i]=="t" then
  467.       countT=countT+1
  468.     end
  469.   end
  470.   return countA,countB,countT,countA+countB+countT
  471.  
  472. end
  473.  
  474.  
  475.  
  476. ------------------------------------------------------------------------------
  477. -- main: description ---------------------------------------------------------
  478. ------------------------------------------------------------------------------
  479. checkTurtle(true)
  480.  
  481. local iPage=0
  482. if blnAskForParameters then
  483. term.clear() term.setCursorPos(1,1)
  484. local iPageMax=3                                    
  485. local event, key, isHeld  
  486. local blnLoop=true                              
  487.  
  488. term.clear() term.setCursorPos(1,1) iPage=iPage+1
  489. printUI("header")
  490. printUI(""..cPrgName..", "..cVersion..", by Kaikaku ("..iPage.."/"..iPageMax.."+)")
  491. printUI("line")
  492. --       1234567890123456789012345678901234567
  493. printUI("This program can load all other")
  494. printUI("  programs released by Kaikaku.")
  495. printUI("No need to remember any other")
  496. printUI("  pastebin codes than: TUAPv1FU")
  497. printUI("You can select single programs")
  498. printUI("  or groups of programs (e.g. all")
  499. printUI("  builder programs). Or load by ")
  500. printUI("  paramter call: tLoader bDrone")
  501. printUI("footer")
  502.  
  503. coloredTextAt(cPrgName,2,2,baseColor)
  504. coloredTextAt("TUAPv1FU",25,7,baseColor)
  505. coloredTextAt("tLoader bDrone",19,11,baseColor)
  506. pressKeyNoSpecials("Press key for next (stop w/ ctrl+t)   ")  
  507.  
  508.  
  509.  
  510. term.clear() term.setCursorPos(1,1) iPage=iPage+1
  511. printUI("header")
  512. printUI(""..cPrgName..", "..cVersion..", by Kaikaku ("..iPage.."/"..iPageMax.."+)")
  513. printUI("line")
  514. --       1234567890123456789012345678901234567
  515. printUI("How to remember TUAPv1FU?")
  516. printUI("  T  = To                    It took ")
  517. printUI("  U  = YOU                   quite a ")
  518. printUI("  A  = All                   while   ")
  519. printUI("  P  = Programs              and a   ")
  520. printUI("  v  = version               temp ban")
  521. printUI("  1  = one                   to get  ")
  522. printUI("  FU = FU**?!                this  ")
  523. --       1234567890123456789012345678901234567
  524. printUI("footer")
  525.  
  526. coloredTextAt(cPrgName,2,2,baseColor)
  527. coloredTextAt("TUAPv1FU",18,4,baseColor)
  528. coloredTextAt("T",4,5,baseColor) coloredTextAt("T",9,5,baseColor)
  529. coloredTextAt("U",4,6,baseColor) coloredTextAt("YOU",9,6,baseColor)
  530. coloredTextAt("A",4,7,baseColor) coloredTextAt("A",9,7,baseColor)
  531. coloredTextAt("P",4,8,baseColor) coloredTextAt("P",9,8,baseColor)
  532. coloredTextAt("v",4,9,baseColor) coloredTextAt("v",9,9,baseColor)
  533. coloredTextAt("1",4,10,baseColor) coloredTextAt("one",9,10,baseColor)
  534. coloredTextAt("FU",4,11,baseColor) coloredTextAt("FU",9,11,baseColor)
  535.  
  536.  
  537. pressKeyNoSpecials("Press key for next (stop w/ ctrl+t)   ")
  538.  
  539.  
  540. term.clear() term.setCursorPos(1,1) iPage=iPage+1
  541. local aa,bb,tt,ss = countProgramTypes()
  542. printUI("header")
  543. printUI(""..cPrgName..", "..cVersion..", by Kaikaku ("..iPage.."/"..iPageMax.."+)")
  544. printUI("line")
  545. --       1234567890123456789012345678901234567
  546. printUI("Select load mode:")
  547. printUI("  1 = select one from list (1)")
  548. printUI("  2 = all automation programs ("..aa..")")
  549. printUI("  3 = all building programs ("..bb..")")
  550. printUI("  4 = all tool programs ("..tt..")")
  551. printUI("  5 = all programs ("..(#array/4)..")")
  552. printUI("  ")
  553. printUI("  d = delete old programs (off)")
  554. printUI("footer")
  555. term.write("Press key 1,2,3,4,5 to select mode")
  556.  
  557. coloredTextAt(cPrgName,2,2,baseColor)
  558. coloredTextAt("Select load mode",2,4,baseColor)
  559. coloredTextAt("1",4,5,baseColor)  coloredTextAt("list", 24,5,baseColor)
  560. coloredTextAt("2",4,6,baseColor)  coloredTextAt("a",    12,6,colors.green)
  561. coloredTextAt("3",4,7,baseColor)  coloredTextAt("b",    12,7,colors.red)
  562. coloredTextAt("4",4,8,baseColor)  coloredTextAt("t",    12,8,baseColor)
  563. coloredTextAt("5",4,9,baseColor)  coloredTextAt("all",   8,9,baseColor)
  564. coloredTextAt("d",4,11,baseColor) coloredTextAt("(off)",28,11,baseColor)
  565.  
  566. while blnLoop do -- option selection example --<< example to check for 1,2,3,4
  567.   event, key, isHeld = os.pullEvent("key")
  568.   if key~=nil then
  569.     if keys.getName(key)=="one"
  570.     or keys.getName(key)=="two"
  571.     or keys.getName(key)=="three"
  572.     or keys.getName(key)=="four"  
  573.     or keys.getName(key)=="five" then
  574.       blnLoop=false
  575.     elseif keys.getName(key)=="d" then
  576.       if blnDelete then
  577.         blnDelete=false
  578.         coloredTextAt("(off)",28,11,baseColor)
  579.       else
  580.         blnDelete=true
  581.         coloredTextAt("(on) ",28,11,baseColor)
  582.       end
  583.     end
  584.   end
  585. end
  586.  
  587. if keys.getName(key)=="two" then blnAllA=true
  588. elseif keys.getName(key)=="three" then blnAllB=true
  589. elseif keys.getName(key)=="four" then blnAllT=true
  590. elseif keys.getName(key)=="five" then blnAll=true
  591. end
  592.  
  593. if keys.getName(key)=="one" then
  594. local cRowCount=8
  595. local iNumber
  596. local iNumberLast
  597. local blnSelectionDone=false
  598.  
  599. --local function arrangeArray(inputArray, startAt, endAt, widthAt, maxRows, maxCharacters, numSpacers)
  600.   local testArray = arrangeArray(array,1,nil,4,#array/4,16,1)
  601.   local numberPages = math.ceil(#testArray/cRowCount)
  602.   iPageMax=iPageMax+numberPages
  603.   for j=1,#array/4,cRowCount do
  604.     term.clear() term.setCursorPos(1,1) iPage=iPage+1
  605.     printUI("header")
  606.     printUI(""..cPrgName..", "..cVersion..", by Kaikaku ("..iPage.."/"..iPageMax..")")
  607.     printUI("line")
  608.     coloredTextAt(cPrgName,2,2,baseColor)
  609.  
  610.     iNumber=1
  611.     iNumberLast=1
  612.     for i=j,j+cRowCount-1,1 do
  613.      
  614.       if testArray[i]~= nil then
  615.         printUI("  "..iNumber.." = "..testArray[i])
  616.         coloredTextAt(iNumber,4,3+iNumber,baseColor)
  617.         if string.sub(testArray[i],1,1)=="a" then coloredTextAt("a" ,8,3+iNumber,colors.green)
  618.         elseif string.sub(testArray[i],1,1)=="b" then coloredTextAt("b" ,8,3+iNumber,colors.red)
  619.         elseif string.sub(testArray[i],1,1)=="t" then coloredTextAt("t" ,8,3+iNumber,colors.blue)
  620.         end
  621.         iNumberLast=iNumberLast+1
  622.       else
  623.         printUI()
  624.       end
  625.       iNumber=iNumber+1
  626.     end
  627.     printUI("footer")
  628.     if iPage<iPageMax then
  629.       term.write("Select program (1-"..(iNumberLast-1).."), other key = next ")
  630.     else
  631.       term.write("Select program (1-"..(iNumberLast-1).."), other key = EXIT ")
  632.     end
  633.    
  634.     blnLoop=true
  635.     local iArray
  636.     while blnLoop do
  637.       event, key, isHeld = os.pullEvent("key")
  638.       if key~=nil then
  639.         if keys.getName(key)=="one" and iNumberLast>1 then
  640.           iArray=1
  641.           iArray=iArray+(iPage-3-1)*4*cRowCount
  642.           singleProg1=array[iArray]..array[iArray+1]
  643.           blnSelectionDone=true
  644.         elseif keys.getName(key)=="two" and iNumberLast>2 then
  645.           iArray=1+1*4
  646.           iArray=iArray+(iPage-3-1)*4*cRowCount
  647.           singleProg1=array[iArray]..array[iArray+1]
  648.           blnSelectionDone=true
  649.         elseif keys.getName(key)=="three" and iNumberLast>3 then
  650.           iArray=1+2*4
  651.           iArray=iArray+(iPage-3-1)*4*cRowCount
  652.           singleProg1=array[iArray]..array[iArray+1]
  653.           blnSelectionDone=true
  654.         elseif keys.getName(key)=="four" and iNumberLast>4 then
  655.           iArray=1+3*4
  656.           iArray=iArray+(iPage-3-1)*4*cRowCount
  657.           singleProg1=array[iArray]..array[iArray+1]
  658.           blnSelectionDone=true
  659.         elseif keys.getName(key)=="five" and iNumberLast>5 then
  660.           iArray=1+4*4
  661.           iArray=iArray+(iPage-3-1)*4*cRowCount
  662.           singleProg1=array[iArray]..array[iArray+1]
  663.           blnSelectionDone=true
  664.         elseif keys.getName(key)=="six" and iNumberLast>6 then
  665.           iArray=1+5*4
  666.           iArray=iArray+(iPage-3-1)*4*cRowCount
  667.           singleProg1=array[iArray]..array[iArray+1]
  668.           blnSelectionDone=true
  669.         elseif keys.getName(key)=="seven" and iNumberLast>7 then
  670.           iArray=1+6*4
  671.           iArray=iArray+(iPage-3-1)*4*cRowCount
  672.           singleProg1=array[iArray]..array[iArray+1]
  673.           blnSelectionDone=true
  674.         elseif keys.getName(key)=="eight" and iNumberLast>8 then
  675.           iArray=1+7*4
  676.           iArray=iArray+(iPage-3-1)*4*cRowCount
  677.           singleProg1=array[iArray]..array[iArray+1]
  678.           blnSelectionDone=true
  679.         end
  680.         blnLoop=false
  681.       end
  682.     end
  683.     if blnSelectionDone then break end
  684.   end
  685. end
  686. end
  687.  
  688.    
  689. ---------------------------------------
  690. ---- MAIN -----------------------------
  691. ---------------------------------------
  692. term.clear() term.setCursorPos(1,1)
  693.  
  694. ---- step 1: pastebin get ----  
  695. print("step 1: pastebin get...")
  696. local i=1
  697.  
  698. while array[i]~=nil do
  699.   if blnAll
  700.   or (blnAllA and array[i]=="a")
  701.   or (blnAllT and array[i]=="t")
  702.   or (blnAllB and array[i]=="b")
  703.   or string.lower(singleProg1)==string.lower(array[i]..array[i+1])
  704.   or string.lower(singleProg2)==string.lower(array[i]..array[i+1])
  705.   or string.lower(singleProg3)==string.lower(array[i]..array[i+1]) then
  706.     print("-- "..array[i]..array[i+1].." --")
  707.     if blnDelete then
  708.       print("Deleting current version")
  709.       shell.run("delete "..array[i]..array[i+1])
  710.     end
  711.     print(shell.run("pastebin get "..array[i+2].." "..array[i]..array[i+1]))
  712.     counter=counter+1
  713.     sleep(cSleepTime)
  714.   end
  715.   i=i+4
  716. end
  717.  
  718. if counter~=0 then
  719.   sleepDots(6,0.2)
  720.   ---- step 2: finishing stuff / report ----
  721.   term.clear() term.setCursorPos(1,1)
  722.   print("step 2: report")
  723.   if counter==1 then
  724.     print("1 program downloaded/updated/tried :)")
  725.   else
  726.     print(counter.." programs downloaded/updated/tried :)")
  727.   end
  728. end
  729.  
  730. print()
  731. printUI("header")
  732.        --1234567890123456789012345678901234567
  733. printUI("If in-program info is insufficient,")
  734. printUI("you can check out YouTube for further")
  735. printUI("explanations. Just search for the")
  736. printUI("program name and ComputerCraft.")
  737. printUI("Enjoy! Kaikaku ")
  738. coloredTextAt("Kaikaku",9,9,baseColor)
  739. printUI("footer")
  740.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement