Bjoerniboii

New Reactor Control

Oct 26th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.34 KB | None | 0 0
  1. -- ****************************************************** --
  2. -- ****************************************************** --
  3. -- ** Reactor Madness Program ** --
  4. -- ** for Big Reactor ** --
  5. -- ** Written by Bjoerniboii ** --
  6. -- ** Video Tutorial ** --
  7. -- ** https://www.youtube.com/watch?v=SbbT7ncyS2M ** --
  8. -- ****************************************************** --
  9. -- ****************************************************** --
  10.  
  11.  
  12.  
  13.  
  14. local monitors = {peripheral.find("monitor")}
  15. local mon = monitors[1]
  16. local reactors = {peripheral.find("BigReactors-Reactor")}
  17.  
  18. local button={}
  19. local filleds = {}
  20. local boxes = {}
  21. local lines = {}
  22. local texts = {}
  23.  
  24. local refresh = true
  25.  
  26. local infosSize = {}
  27. local contorlsSize = {}
  28. local numbersSize = {}
  29. local currentRfTotal = 1
  30. local currentRfTick = 1
  31. local currentFuelConsumedLastTick = 0.00001
  32.  
  33.  
  34. local rfPerTickMax = 1
  35. local minPowerRod = 0
  36. local maxPowerRod = 100
  37. local currentRodLevel = 1
  38.  
  39. -- you need to give the index to be able to use the program
  40. -- ex : NameOfProgram Index (reactor Bjoerniboii)
  41.  
  42. local args = { ... }
  43. local index = ""
  44.  
  45. if (#args == 0) then
  46. error("No index Given")
  47. end
  48.  
  49. if (#args == 1) then
  50. index = args[1]
  51. end
  52.  
  53. -- use the black thingy sponge to clear the chalkboard
  54.  
  55. term.redirect(mon)
  56. mon.clear()
  57. mon.setTextColor(colors.white)
  58. mon.setBackgroundColor(colors.black)
  59.  
  60. function clearTable()
  61. button = {}
  62. end
  63.  
  64. -- All the things that make my buttons work
  65.  
  66. function setButton(name, title, func, xmin, ymin, xmax, ymax, elem, elem2, color)
  67. button[name] = {}
  68. button[name]["title"] = title
  69. button[name]["func"] = func
  70. button[name]["active"] = false
  71. button[name]["xmin"] = xmin
  72. button[name]["ymin"] = ymin
  73. button[name]["xmax"] = xmax
  74. button[name]["ymax"] = ymax
  75. button[name]["color"] = color
  76. button[name]["elem"] = elem
  77. button[name]["elem2"] = elem2
  78. end
  79.  
  80. -- stuff and things for buttons
  81.  
  82. function fill(text, color, bData)
  83. mon.setBackgroundColor(color)
  84. mon.setTextColor(colors.white)
  85. local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  86. local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(bData["title"])) /2) +1
  87. for j = bData["ymin"], bData["ymax"] do
  88. mon.setCursorPos(bData["xmin"], j)
  89. if j == yspot then
  90. for k = 0, bData["xmax"] - bData["xmin"] - string.len(bData["title"]) +1 do
  91. if k == xspot then
  92. mon.write(bData["title"])
  93. else
  94. mon.write(" ")
  95. end
  96. end
  97. else
  98. for i = bData["xmin"], bData["xmax"] do
  99. mon.write(" ")
  100. end
  101. end
  102. end
  103. mon.setBackgroundColor(colors.black)
  104. end
  105.  
  106. -- stuff and things for buttons
  107.  
  108. function screen()
  109. local currColor
  110. for name,data in pairs(button) do
  111. local on = data["active"]
  112. currColor = data["color"]
  113. fill(name, currColor, data)
  114. end
  115. end
  116.  
  117. -- stuff and things for buttons
  118.  
  119. function flash(name)
  120.  
  121. screen()
  122. end
  123.  
  124. -- magical handler for clicky clicks
  125.  
  126. function checkxy(x, y)
  127. for name, data in pairs(button) do
  128. if y>=data["ymin"] and y <= data["ymax"] then
  129. if x>=data["xmin"] and x<= data["xmax"] then
  130. data["func"](data["elem"], data["elem2"])
  131. flash(data['name'])
  132. return true
  133. --data["active"] = not data["active"]
  134. --print(name)
  135. end
  136. end
  137. end
  138. return false
  139. end
  140.  
  141. -- Don't question my code, it works on my machine...
  142.  
  143. function label(w, h, text)
  144. mon.setCursorPos(w, h)
  145. mon.write(text)
  146. end
  147.  
  148. -- Draw function : put's all the beautiful magic in the screen
  149.  
  150. function draw()
  151.  
  152. for key,value in pairs(filleds) do
  153. paintutils.drawFilledBox(value[1] , value[2], value[3], value[4], value[5])
  154. end
  155.  
  156. for key,value in pairs(boxes) do
  157. paintutils.drawBox(value[1] , value[2], value[3], value[4], value[5])
  158. end
  159.  
  160. for key,value in pairs(lines) do
  161. paintutils.drawLine(value[1] , value[2], value[3], value[4], value[5])
  162. end
  163.  
  164. for key,value in pairs(texts) do
  165. mon.setCursorPos(value[1], value[2])
  166. mon.setTextColor(value[4])
  167. mon.setBackgroundColor(value[5])
  168. mon.write(value[3])
  169. end
  170. screen()
  171. resetDraw()
  172. end
  173.  
  174. -- Resets the elements to draw to only draw the neccessity
  175.  
  176. function resetDraw()
  177. filleds = {}
  178. boxes = {}
  179. lines = {}
  180. texts = {}
  181. end
  182.  
  183. -- Handles all the clicks for the buttons
  184.  
  185. function clickEvent()
  186. local myEvent={os.pullEvent("monitor_touch")}
  187. checkxy(myEvent[3], myEvent[4])
  188. end
  189.  
  190. -- Power up the reactor (M&N are a good source of food right?)
  191.  
  192. function powerUp(m,n)
  193. local reactor = reactors[1]
  194. reactor.setActive(true)
  195. end
  196.  
  197. -- Power down the reactor (M&N are a good source of food right?)
  198.  
  199. function powerDown(m,n)
  200. local reactor = reactors[1]
  201. reactor.setActive(false)
  202. end
  203.  
  204. -- Handles and calculate the Min and Max of the power limitation
  205.  
  206. function modifyRods(limit, number)
  207. local tempLevel = 0
  208.  
  209. if limit == "min" then
  210. tempLevel = minPowerRod + number
  211. if tempLevel <= 0 then
  212. minPowerRod = 0
  213. end
  214.  
  215. if tempLevel >= maxPowerRod then
  216. minPowerRod = maxPowerRod -10
  217. end
  218.  
  219. if tempLevel < maxPowerRod and tempLevel > 0 then
  220. minPowerRod = tempLevel
  221. end
  222. else
  223. tempLevel = maxPowerRod + number
  224. if tempLevel <= minPowerRod then
  225. maxPowerRod = minPowerRod +10
  226. end
  227.  
  228. if tempLevel >= 100 then
  229. maxPowerRod = 100
  230. end
  231.  
  232. if tempLevel > minPowerRod and tempLevel < 100 then
  233. maxPowerRod = tempLevel
  234. end
  235. end
  236.  
  237. table.insert(lines, {contorlsSize['inX'], contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, contorlsSize['inX'] + contorlsSize['width'], contorlsSize['inY']+(contorlsSize['sectionHeight']*1)+4, colors.black})
  238.  
  239. table.insert(texts, {contorlsSize['inX']+5, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, minPowerRod .. '%', colors.lightBlue, colors.black})
  240. table.insert(texts, {contorlsSize['inX']+13, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, '--', colors.white, colors.black})
  241. table.insert(texts, {contorlsSize['inX']+20, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, maxPowerRod .. '%', colors.purple, colors.black})
  242.  
  243. setInfoToFile()
  244. adjustRodsLevel()
  245. end
  246.  
  247. -- Calculate and adjusts the level of the rods
  248.  
  249. function adjustRodsLevel()
  250. local reactor = reactors[1]
  251. local rfTotalMax = 10000000
  252. local currentRfTotal = reactor.getEnergyStored()
  253.  
  254. differenceMinMax = maxPowerRod - minPowerRod
  255.  
  256. maxPower = (rfTotalMax/100) * maxPowerRod
  257. minPower = (rfTotalMax/100) * minPowerRod
  258.  
  259. if currentRfTotal >= maxPower then
  260. currentRfTotal = maxPower
  261. end
  262.  
  263. if currentRfTotal <= minPower then
  264. currentRfTotal = minPower
  265. end
  266.  
  267. currentRfTotal = currentRfTotal - (rfTotalMax/100) * minPowerRod
  268.  
  269. local rfInBetween = (rfTotalMax/100) * differenceMinMax
  270. local rodLevel = math.ceil((currentRfTotal/rfInBetween)*100)
  271.  
  272. reactor.setAllControlRodLevels(rodLevel)
  273. end
  274.  
  275. -- Creates the frame and the basic of the visual
  276. -- Also adds the variables informations for placement of stuff and things
  277.  
  278. function addDrawBoxesSingleReactor()
  279. local w, h = mon.getSize()
  280. local margin = math.floor((w/100)*2)
  281.  
  282. infosSize['startX'] = margin + 1
  283. infosSize['startY'] = margin + 1
  284. infosSize['endX'] = (((w-(margin*2))/3)*2)-margin
  285. infosSize['endY'] = h - margin
  286. infosSize['height'] = infosSize['endY']-infosSize['startY']-(margin*2)-2
  287. infosSize['width'] = infosSize['endX']-infosSize['startX']-(margin*2)-2
  288. infosSize['inX'] = infosSize['startX'] + margin +1
  289. infosSize['inY'] = infosSize['startY'] + margin +1
  290. infosSize['sectionHeight'] = math.floor(infosSize['height']/3)
  291.  
  292. table.insert(boxes, {infosSize['startX'] , infosSize['startY'], infosSize['endX'], infosSize['endY'], colors.gray})
  293. local name = "INFOS"
  294. table.insert(lines, {infosSize['startX'] + margin , infosSize['startY'], infosSize['startX'] + (margin*2) + #name+1, infosSize['startY'], colors.black})
  295. table.insert(texts, {infosSize['startX'] + (margin*2), infosSize['startY'], name, colors.white, colors.black})
  296.  
  297. local names = {}
  298. names[1] = 'ENERGY LAST TICK'
  299. names[2] = 'ENERGY STORED'
  300. names[3] = 'CONTROL ROD LEVEL'
  301.  
  302. for i=0,2,1 do
  303. table.insert(texts, {infosSize['inX'] + margin, infosSize['inY'] + (infosSize['sectionHeight']*i) +i, names[i+1], colors.white, colors.black})
  304. table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 2 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
  305. end
  306.  
  307.  
  308. -- Controls
  309.  
  310. contorlsSize['startX'] = infosSize['endX'] + margin + 1
  311. contorlsSize['startY'] = margin + 1
  312. contorlsSize['endX'] = w-margin
  313. contorlsSize['endY'] = (((h - (margin*2))/3)*2) +1
  314. contorlsSize['height'] = contorlsSize['endY']-contorlsSize['startY']-(margin)-1
  315. contorlsSize['width'] = contorlsSize['endX']-contorlsSize['startX']-(margin*2)-2
  316. contorlsSize['inX'] = contorlsSize['startX'] + margin +1
  317. contorlsSize['inY'] = contorlsSize['startY'] + margin
  318.  
  319. table.insert(boxes, {contorlsSize['startX'] , contorlsSize['startY'], contorlsSize['endX'], contorlsSize['endY'], colors.gray})
  320. name = "CONTROLS"
  321. table.insert(lines, {contorlsSize['startX'] + margin , contorlsSize['startY'], contorlsSize['startX'] + (margin*2) + #name+1, contorlsSize['startY'], colors.black})
  322. table.insert(texts, {contorlsSize['startX'] + (margin*2), contorlsSize['startY'], name, colors.white, colors.black})
  323.  
  324. contorlsSize['sectionHeight'] = math.floor(contorlsSize['height']/4)
  325.  
  326. reactor = reactors[1]
  327.  
  328. mon.setTextColor(colors.white)
  329. setButton("ON","ON", powerUp, contorlsSize['inX'], contorlsSize['inY'], contorlsSize['inX'] + math.floor(contorlsSize['width']/2) -1, contorlsSize['inY'] +2, 0, 0, colors.green)
  330. setButton("OFF","OFF", powerDown, contorlsSize['inX'] + math.floor(contorlsSize['width']/2) +2, contorlsSize['inY'], contorlsSize['inX'] + contorlsSize['width'], contorlsSize['inY'] +2,0, 0, colors.red)
  331.  
  332. table.insert(texts, {contorlsSize['inX']+8, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+1, 'AUTO-CONTROL', colors.white, colors.black})
  333.  
  334. table.insert(texts, {contorlsSize['inX']+5, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+3, 'MIN', colors.lightBlue, colors.black})
  335. table.insert(texts, {contorlsSize['inX']+5, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, minPowerRod..'%', colors.lightBlue, colors.black})
  336.  
  337. table.insert(texts, {contorlsSize['inX']+13, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, '--', colors.white, colors.black})
  338. table.insert(texts, {contorlsSize['inX']+20, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+3, 'MAX', colors.purple, colors.black})
  339. table.insert(texts, {contorlsSize['inX']+20, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, maxPowerRod..'%', colors.purple, colors.black})
  340. mon.setTextColor(colors.white)
  341.  
  342. setButton("low-10","-10", modifyRods, contorlsSize['inX'], contorlsSize['inY'] +(contorlsSize['sectionHeight']*2)+2, contorlsSize['inX'] + math.floor(contorlsSize['width']/2) -1, contorlsSize['inY'] +(contorlsSize['sectionHeight']*2)+4, "min", -10, colors.lightBlue)
  343. setButton("high-10","-10", modifyRods, contorlsSize['inX'] + math.floor(contorlsSize['width']/2) +2, contorlsSize['inY'] +(contorlsSize['sectionHeight']*2)+2, contorlsSize['inX'] + contorlsSize['width'], contorlsSize['inY'] +(contorlsSize['sectionHeight']*2)+4, "max", -10, colors.purple)
  344.  
  345. setButton("low+10","+10", modifyRods, contorlsSize['inX'], contorlsSize['inY'] +(contorlsSize['sectionHeight']*3)+2, contorlsSize['inX'] + math.floor(contorlsSize['width']/2) -1, contorlsSize['inY'] +(contorlsSize['sectionHeight']*3)+4, "min", 10, colors.lightBlue)
  346. setButton("high+10","+10", modifyRods, contorlsSize['inX'] + math.floor(contorlsSize['width']/2) +2, contorlsSize['inY'] +(contorlsSize['sectionHeight']*3)+2, contorlsSize['inX'] + contorlsSize['width'], contorlsSize['inY'] +(contorlsSize['sectionHeight']*3)+4, "max", 10, colors.purple)
  347.  
  348. -- Numbers
  349.  
  350. numbersSize['startX'] = infosSize['endX'] + margin + 1
  351. numbersSize['startY'] = contorlsSize['endY'] + margin + 1
  352. numbersSize['endX'] = w-margin
  353. numbersSize['endY'] = h-margin
  354. numbersSize['height'] = numbersSize['endY']-numbersSize['startY']-(margin)-1
  355. numbersSize['width'] = numbersSize['endX']-numbersSize['startX']-(margin*2)-2
  356. numbersSize['inX'] = numbersSize['startX'] + margin +1
  357. numbersSize['inY'] = numbersSize['startY'] + margin
  358.  
  359. table.insert(boxes, {numbersSize['startX'] , numbersSize['startY'], numbersSize['endX'], numbersSize['endY'], colors.gray})
  360. name = "NUMBERS"
  361. table.insert(lines, {numbersSize['startX'] + margin , numbersSize['startY'], numbersSize['startX'] + (margin*2) + #name+1, numbersSize['startY'], colors.black})
  362. table.insert(texts, {numbersSize['startX'] + (margin*2), numbersSize['startY'], name, colors.white, colors.black})
  363.  
  364. refresh = true
  365. while refresh do
  366. parallel.waitForAny(refreshSingleReactor,clickEvent)
  367. end
  368. end
  369.  
  370. -- Makes and Handles the draw function for less lag in the visual
  371.  
  372. function refreshSingleReactor()
  373. local rfPerTick = 0
  374. local rfTotal = 0
  375. local rfTotalMax = 10000000
  376. local reactor = reactors[1]
  377.  
  378. rfTotal = reactor.getEnergyStored()
  379. rfPerTick = math.floor(reactor.getEnergyProducedLastTick())
  380. rodLevel = math.floor(reactor.getControlRodLevel(0))
  381. fuelPerTick = reactor.getFuelConsumedLastTick();
  382.  
  383. local i = 0
  384. local infotoAdd = 'RF PER TICK : '
  385.  
  386. if currentRfTick ~= rfPerTick then
  387. currentRfTick = rfPerTick
  388. if rfPerTick > rfPerTickMax then
  389. rfPerTickMax = rfPerTick
  390. end
  391.  
  392. table.insert(lines, {numbersSize['inX'] , numbersSize['inY'],numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'], colors.black})
  393. table.insert(texts, {numbersSize['inX'], numbersSize['inY'], infotoAdd .. rfPerTick .. " RF", colors.white, colors.black})
  394. table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
  395.  
  396. width = math.floor((infosSize['width'] / rfPerTickMax)*rfPerTick)
  397. table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green})
  398.  
  399. end
  400.  
  401. i = 1
  402. infotoAdd = 'ENERGY STORED : '
  403. if currentRfTotal ~= rfTotal then
  404. currentRfTotal = rfTotal
  405.  
  406. table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
  407.  
  408. width = math.floor((infosSize['width'] / rfTotalMax)*rfTotal)
  409. table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green})
  410. table.insert(lines, {numbersSize['inX'] , numbersSize['inY'] +2 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +2, colors.black})
  411. table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 2 , infotoAdd .. rfTotal .. " RF", colors.white, colors.black})
  412. end
  413.  
  414. i = 2
  415. infotoAdd = 'CONTROL ROD LEVEL : '
  416. if currentRodLevel ~= rodLevel then
  417. currentRodLevel = rodLevel
  418.  
  419. table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
  420.  
  421. width = math.floor((infosSize['width'] / 100)*rodLevel)
  422. table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green})
  423. table.insert(lines, {numbersSize['inX'] , numbersSize['inY']+4 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +4, colors.black})
  424. table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 4 , infotoAdd .. rodLevel .. "%", colors.white, colors.black})
  425. end
  426.  
  427. i = 3
  428. infotoAdd = 'FUEL USAGE : '
  429. if currentFuelConsumedLastTick ~= fuelPerTick then
  430. currentFuelConsumedLastTick = fuelPerTick
  431.  
  432. table.insert(lines, {numbersSize['inX'] , numbersSize['inY']+6 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +6, colors.black})
  433. table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 6 , infotoAdd .. format_num(tonumber(fuelPerTick),3) .. "mb/t", colors.white, colors.black})
  434. end
  435.  
  436. mon.setTextColor(colors.white)
  437. adjustRodsLevel()
  438.  
  439. draw()
  440.  
  441. sleep(2)
  442. end
  443.  
  444. --
  445. -- ** Get the informations from the index file
  446. -- line 1 = min ROD
  447. -- line 2 = max ROD
  448. --
  449.  
  450. function getInfoFromFile()
  451.  
  452. if (fs.exists(index..".txt") == false) then
  453. file = io.open(index..".txt","w")
  454. file:write("0")
  455. file:write("\n")
  456. file:write("100")
  457. file:close()
  458. else
  459. file = fs.open(index..".txt","r")
  460. minPowerRod = tonumber(file.readLine())
  461. maxPowerRod = tonumber(file.readLine())
  462. file.close()
  463. end
  464. end
  465.  
  466. -- Save informations to the index file
  467.  
  468. function setInfoToFile()
  469. file = io.open(index..".txt","w")
  470. file:write(minPowerRod .. "\n" .. maxPowerRod)
  471. file:flush()
  472. file:close()
  473. end
  474.  
  475. ---============================================================
  476. -- add comma to separate thousands
  477. -- From Lua-users.org/wiki/FormattingNumbers
  478. --
  479. --
  480. function comma_value(amount)
  481. local formatted = amount
  482. while true do
  483. formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
  484. if (k==0) then
  485. break
  486. end
  487. end
  488. return formatted
  489. end
  490.  
  491. ---============================================================
  492. -- rounds a number to the nearest decimal places
  493. -- From Lua-users.org/wiki/FormattingNumbers
  494. --
  495. --
  496. function round(val, decimal)
  497. if (decimal) then
  498. return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
  499. else
  500. return math.floor(val+0.5)
  501. end
  502. end
  503.  
  504. --===================================================================
  505. -- given a numeric value formats output with comma to separate thousands
  506. -- and rounded to given decimal places
  507. -- From Lua-users.org/wiki/FormattingNumbers
  508. --
  509. function format_num(amount, decimal, prefix, neg_prefix)
  510. local str_amount, formatted, famount, remain
  511.  
  512. decimal = decimal or 2 -- default 2 decimal places
  513. neg_prefix = neg_prefix or "-" -- default negative sign
  514.  
  515. famount = math.abs(round(amount,decimal))
  516. famount = math.floor(famount)
  517.  
  518. remain = round(math.abs(amount) - famount, decimal)
  519.  
  520. -- comma to separate the thousands
  521. formatted = comma_value(famount)
  522.  
  523. -- attach the decimal portion
  524. if (decimal > 0) then
  525. remain = string.sub(tostring(remain),3)
  526. formatted = formatted .. "." .. remain ..
  527. string.rep("0", decimal - string.len(remain))
  528. end
  529.  
  530. -- attach prefix string e.g '$'
  531. formatted = (prefix or "") .. formatted
  532.  
  533. -- if value is negative then format accordingly
  534. if (amount<0) then
  535. if (neg_prefix=="()") then
  536. formatted = "("..formatted ..")"
  537. else
  538. formatted = neg_prefix .. formatted
  539. end
  540. end
  541.  
  542. return formatted
  543. end
  544.  
  545. -- Clear and make the pixel smaller because we are not blind
  546.  
  547. mon.setBackgroundColor(colors.black)
  548. mon.clear()
  549. mon.setTextScale(0.5)
  550.  
  551. -- Get the information from the index file
  552. getInfoFromFile()
  553.  
  554.  
  555. -- Add's the visual and starts the Loop
  556. addDrawBoxesSingleReactor()
Advertisement
Add Comment
Please, Sign In to add comment