Advertisement
bryceio

Computercraft Bry API V1

May 30th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.08 KB | None | 0 0
  1. --Rounds decimals.
  2. --Put input in parenthesis
  3. --Output is (rounded)
  4. function round(number)
  5.   roundUp = (math.ceil(number)-number)
  6.   roundDown = (number - math.floor(number))
  7.     if roundUp <= roundDown then
  8.       rounded = math.ceil(number)
  9.      elseif roundUp > roundDown then
  10.       rounded = math.floor(number)
  11.     end
  12.   return rounded
  13. end
  14.  
  15. --Clears screen and sets cursor to top
  16. function resetCursor()
  17.   term.clear()
  18.   term.setCursorPos(1, 1)
  19. end
  20.  
  21. --Checks if a number is even.
  22. function isEven(number)
  23.   if (number/2) == bry.round(number/2) then
  24.     return true
  25.   else
  26.     return false
  27.   end
  28. end  
  29.  
  30. --Emits a 1/2 second redstone pulse.
  31. function redPulse(side)
  32.  redstone.setOutput(side, true)
  33.  sleep(0.5)
  34.  redstone.setOutput(side, false)
  35. end
  36.  
  37. --Changes terminal text color if it can
  38. function textColor(color)
  39.     if term.isColor() then
  40.         term.setTextColor(color)
  41.     end
  42. end
  43.  
  44. --Averages a table of numbers
  45. function average(table)
  46.     i = 1
  47.     temp = 0
  48.     while i < #table + 1 do
  49.         temp = temp + table[i]
  50.         i = i + 1
  51.     end
  52.     result = temp/#table
  53.     return(result)
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement