Xgamer911

RIM-Frame_Control

Nov 26th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.65 KB | None | 0 0
  1. --DIRECTIONS
  2. --Create file in main folder of computer named "mylog.log", this file hold variables though reboots.
  3. -- 0 down
  4. -- 1 up
  5. -- 2 north
  6. -- 3 south
  7. -- 4 west
  8. -- 5 east
  9.  
  10.  
  11.  
  12. local w,h = term.getSize()
  13. drive=peripheral.wrap("top")
  14. local selection = 0
  15. local internalselection = 0
  16. local int range = 0
  17. local currentrange = 0
  18. local ypos = 1
  19. local counter = 1
  20. local direction
  21.  
  22. --Some draw functions to get us started
  23. local function printCentered(str, ypos)
  24. term.setCursorPos(w/2 - #str/2, ypos)
  25. term.write(str)
  26. end
  27.  
  28. local function printFarLeft(str, ypos)
  29. term.setCursorPos(1, ypos)
  30. term.write(str)
  31. end
  32.  
  33. local function printLeft(str, ypos)
  34. term.setCursorPos(5, ypos)
  35. term.write(str)
  36. end
  37.  
  38. local function printLeft2(str, ypos)
  39. term.setCursorPos(10, ypos)
  40. term.write(str)
  41. end
  42.  
  43. local function printRight(str, ypos)
  44. term.setCursorPos(w - 15, ypos)
  45. term.write(str)
  46. end
  47.  
  48. local function printRight2(str, ypos)
  49. term.setCursorPos(w - 25, ypos)
  50. term.write(str)
  51. end
  52.  
  53. local function printFarRight(str, ypos)
  54. term.setCursorPos(w - #str, ypos)
  55. term.write(str)
  56. end
  57.  
  58. function drawHeader()
  59. printCentered("Helm Control", 1)
  60. printCentered(string.rep("-", w+1), 2)
  61.  
  62. -- Print Range
  63. printCentered("Range Left "..tostring(range),5)
  64. end
  65.  
  66. function drawMainMenu()
  67. printLeft2("1. North", 7)
  68. printRight("5. Up", 7)
  69.  
  70. printLeft2("2. South", 8)
  71. printRight("6. Down", 8)
  72.  
  73. printLeft2("3. West", 9)
  74.  
  75. printLeft2("4. East", 10)
  76. printRight("8. Quit", 10)
  77.  
  78. printLeft2("Selection: ", 12)
  79. selection = tonumber(read())
  80. end
  81.  
  82. function north()
  83. term.clear()
  84. term.setCursorPos(1,1)
  85. internalselection=0
  86. drawHeader()
  87.  
  88. printLeft("Forward", 7)
  89. printLeft("-------", 8)
  90. printLeft("1. Forward 1", 9)
  91. printRight("3. Main Menu", 9)
  92. printLeft("2. Forward range", 10)
  93.  
  94. printLeft("Selection: ", 12)
  95. internalselection = tonumber(read())
  96.  
  97. if internalselection==1 then
  98. direction = 2
  99. --MOVE
  100. drive.move(direction,false,false)
  101. term.clear()
  102. term.setCursorPos(1,1)
  103. end
  104.  
  105. if internalselection==2 then
  106. term.clear()
  107. term.setCursorPos(1,1)
  108.  
  109. drawHeader()
  110.  
  111. printLeft("Forward Range", 7)
  112. printLeft("-------------", 8)
  113. printLeft("How far: ", 9)
  114. currentrange = 0
  115. range = tonumber(read())
  116. direction = 2
  117.  
  118. --Write memory file
  119. startFile = fs.open("mylog.log", "w")
  120. startFile.writeLine(direction)
  121. startFile.writeLine(range)
  122. startFile.close()
  123.  
  124. --MOVE
  125. sleep(1)
  126. drive.move(direction,false,false)
  127. end
  128. end
  129.  
  130. function south()
  131. term.clear()
  132. term.setCursorPos(1,1)
  133. internalselection=0
  134. drawHeader()
  135.  
  136. printLeft("Backward", 7)
  137. printLeft("--------", 8)
  138. printLeft("1. Backward 1", 9)
  139. printRight("3. Main Menu", 9)
  140. printLeft("2. Backward range", 10)
  141.  
  142. printLeft("Selection: ", 12)
  143. internalselection = tonumber(read())
  144.  
  145. if internalselection==1 then
  146. direction = 3
  147. --MOVE
  148. drive.move(direction,false,false)
  149. term.clear()
  150. term.setCursorPos(1,1)
  151. end
  152.  
  153. if internalselection==2 then
  154. term.clear()
  155. term.setCursorPos(1,1)
  156.  
  157. drawHeader()
  158.  
  159. printLeft("Backward Range", 7)
  160. printLeft("-------------", 8)
  161. printLeft("How far: ", 9)
  162. currentrange = 0
  163. range = tonumber(read())
  164. direction = 3
  165.  
  166. --Write memory file
  167. startFile = fs.open("mylog.log", "w")
  168. startFile.writeLine(direction)
  169. startFile.writeLine(range)
  170. startFile.close()
  171.  
  172. --MOVE
  173. sleep(1)
  174. drive.move(direction,false,false)
  175. end
  176.  
  177. if internalselection==3 then
  178. term.clear()
  179. term.setCursorPos(1,1)
  180. internalselection=0
  181. selection=0
  182. main()
  183. end
  184. end
  185.  
  186. function west()
  187. term.clear()
  188. term.setCursorPos(1,1)
  189. internalselection=0
  190. drawHeader()
  191.  
  192. printLeft("West", 7)
  193. printLeft("----", 8)
  194. printLeft("1. West 1", 9)
  195. printRight("3. Main Menu", 9)
  196. printLeft("2. West range", 10)
  197.  
  198. printLeft("Selection: ", 12)
  199. internalselection = tonumber(read())
  200.  
  201. if internalselection==1 then
  202. direction = 4
  203. --MOVE
  204. drive.move(direction,false,false)
  205.  
  206. term.clear()
  207. term.setCursorPos(1,1)
  208. end
  209.  
  210. if internalselection==2 then
  211. term.clear()
  212. term.setCursorPos(1,1)
  213.  
  214. drawHeader()
  215.  
  216. printLeft("Down Range", 7)
  217. printLeft("----------", 8)
  218. printLeft("How far: ", 9)
  219. currentrange = 0
  220. range = tonumber(read())
  221. direction = 4
  222.  
  223. --Write memory file
  224. startFile = fs.open("mylog.log", "w")
  225. startFile.writeLine(direction)
  226. startFile.writeLine(range)
  227. startFile.close()
  228.  
  229. --MOVE
  230. sleep(1)
  231. drive.move(direction,false,false)
  232. end
  233.  
  234. if internalselection==3 then
  235. term.clear()
  236. term.setCursorPos(1,1)
  237. internalselection=0
  238. selection=0
  239. main()
  240. end
  241. end
  242.  
  243. function east()
  244. term.clear()
  245. term.setCursorPos(1,1)
  246. internalselection=0
  247. drawHeader()
  248.  
  249. printLeft("East", 7)
  250. printLeft("----", 8)
  251. printLeft("1. East 1", 9)
  252. printRight("3. Main Menu", 9)
  253. printLeft("2. East range", 10)
  254.  
  255. printLeft("Selection: ", 12)
  256. internalselection = tonumber(read())
  257.  
  258. if internalselection==1 then
  259. direction = 5
  260. --MOVE
  261. drive.move(direction,false,false)
  262.  
  263. term.clear()
  264. term.setCursorPos(1,1)
  265. end
  266.  
  267. if internalselection==2 then
  268. term.clear()
  269. term.setCursorPos(1,1)
  270.  
  271. drawHeader()
  272.  
  273. printLeft("Down Range", 7)
  274. printLeft("----------", 8)
  275. printLeft("How far: ", 9)
  276. currentrange = 0
  277. range = tonumber(read())
  278. direction = 5
  279.  
  280. --Write memory file
  281. startFile = fs.open("mylog.log", "w")
  282. startFile.writeLine(direction)
  283. startFile.writeLine(range)
  284. startFile.close()
  285.  
  286. --MOVE
  287. sleep(1)
  288. drive.move(direction,false,false)
  289. end
  290.  
  291. if internalselection==3 then
  292. term.clear()
  293. term.setCursorPos(1,1)
  294. internalselection=0
  295. selection=0
  296. main()
  297. end
  298. end
  299.  
  300. function up()
  301. term.clear()
  302. term.setCursorPos(1,1)
  303. internalselection=0
  304. drawHeader()
  305.  
  306. printLeft("Up", 7)
  307. printLeft("--", 8)
  308. printLeft("1. Up 1", 9)
  309. printRight("3. Main Menu", 9)
  310. printLeft("2. Up range", 10)
  311.  
  312. printLeft("Selection: ", 12)
  313. internalselection = tonumber(read())
  314.  
  315. if internalselection==1 then
  316. direction = 1
  317. --MOVE
  318. drive.move(direction,false,false)
  319.  
  320. term.clear()
  321. term.setCursorPos(1,1)
  322. end
  323.  
  324. if internalselection==2 then
  325. term.clear()
  326. term.setCursorPos(1,1)
  327.  
  328. drawHeader()
  329.  
  330. printLeft("Up Range", 7)
  331. printLeft("--------", 8)
  332. printLeft("How far: ", 9)
  333. currentrange = 0
  334. range = tonumber(read())
  335. direction = 1
  336.  
  337. --Write memory file
  338. startFile = fs.open("mylog.log", "w")
  339. startFile.writeLine(direction)
  340. startFile.writeLine(range)
  341. startFile.close()
  342.  
  343. --MOVE
  344. sleep(1)
  345. drive.move(direction,false,false)
  346. end
  347.  
  348. if internalselection==3 then
  349. term.clear()
  350. term.setCursorPos(1,1)
  351. internalselection=0
  352. selection=0
  353. main()
  354. end
  355. end
  356.  
  357. function down()
  358. term.clear()
  359. term.setCursorPos(1,1)
  360. internalselection=0
  361. drawHeader()
  362.  
  363. printLeft("Down", 7)
  364. printLeft("----", 8)
  365. printLeft("1. Down 1", 9)
  366. printRight("3. Main Menu", 9)
  367. printLeft("2. Down range", 10)
  368.  
  369. printLeft("Selection: ", 12)
  370. internalselection = tonumber(read())
  371.  
  372. if internalselection==1 then
  373. direction = 0
  374. --MOVE
  375. drive.move(direction,false,false)
  376.  
  377. term.clear()
  378. term.setCursorPos(1,1)
  379. end
  380.  
  381. if internalselection==2 then
  382. term.clear()
  383. term.setCursorPos(1,1)
  384.  
  385. drawHeader()
  386.  
  387. printLeft("Down Range", 7)
  388. printLeft("----------", 8)
  389. printLeft("How far: ", 9)
  390. currentrange = 0
  391. range = tonumber(read())
  392. direction = 0
  393.  
  394. --Write memory file
  395. startFile = fs.open("mylog.log", "w")
  396. startFile.writeLine(direction)
  397. startFile.writeLine(range)
  398. startFile.close()
  399.  
  400. --MOVE
  401. sleep(1)
  402. drive.move(direction,false,false)
  403. end
  404.  
  405. if internalselection==3 then
  406. term.clear()
  407. term.setCursorPos(1,1)
  408. internalselection=0
  409. selection=0
  410. main()
  411. end
  412. end
  413.  
  414. function main()
  415. --PROGRAM START
  416. term.clear()
  417. term.setCursorPos(1,1)
  418.  
  419. myLog = fs.open("myLog.log", "r")
  420. if myLog then
  421. direction = tonumber(myLog.readLine())
  422. range = tonumber(myLog.readLine())
  423. end
  424.  
  425. if (direction ~= "") and (range > 1) then
  426. range = range - 1
  427. startFile = fs.open("mylog.log", "w")
  428. startFile.writeLine(direction)
  429. startFile.writeLine(range)
  430. startFile.close()
  431. sleep(1)
  432. drive.move(direction,false,false)
  433. end
  434.  
  435. while true do
  436. drawHeader()
  437. drawMainMenu()
  438.  
  439.  
  440. if selection==1 then
  441. north()
  442. end
  443.  
  444. if selection==2 then
  445. south()
  446. end
  447.  
  448. if selection==3 then
  449. west()
  450. end
  451.  
  452. if selection==4 then
  453. east()
  454. end
  455.  
  456. if selection==5 then
  457. up()
  458. end
  459.  
  460. if selection==6 then
  461. down()
  462. end
  463.  
  464.  
  465. if selection==8 then
  466. term.clear()
  467. term.setCursorPos(1,1)
  468. break
  469. end
  470.  
  471. end
  472. end
  473.  
  474. main()
Advertisement
Add Comment
Please, Sign In to add comment