XoXFaby

RedScript

Dec 26th, 2012
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.09 KB | None | 0 0
  1. -- RedScript by XoX
  2. -- Please leave this header if you edit this.
  3.  
  4. local tArgs = { ... }
  5.  
  6. if #tArgs == 0 then
  7. print("How would you like to use RedScript?")
  8. print("To load a file type the filename")
  9. print("Other Options: console, help, new")
  10. tArgs[1] = read()
  11. end
  12.  
  13. if tArgs[1] == "console" then
  14. print("Not yet.")
  15. return
  16. end
  17.  
  18. if tArgs[1] == "help" then
  19. print("RedScript allows you to write scripts which use and trigger redstone signals.")
  20. print("Syntax & Functions:")
  21. print("SIDE on/off  = stop or start redstone signal.")
  22. print("wait #       = wait a certain amount of seconds")
  23. print("wait SIDE    = wait for an input for the specified side")
  24. print("goto #       = Go to a certain line in the script")
  25. print("compare a b  = compare 2 variables. if a or b is input the user will be asked to type something")
  26. print("yes COMMAND  = Exeuted if compared variables are the same")
  27. print("no COMMAND   = Executed if they are not")
  28. os.pullEvent("key")
  29. return
  30. end
  31.  
  32. if tArgs[1] == "new" then
  33. term.clear()
  34. term.setCursorPos(1,1)
  35. print("Filename: ")
  36. print("rs_")
  37. term.setCursorPos(4,2)
  38. nfile = tArgs[2] or read()
  39. shell.run("edit", "rs_" .. nfile )
  40. end
  41.  
  42. file = fs.open(tArgs[1], "r")
  43. lines = {}
  44.  
  45. repeat
  46. m = file.readLine()
  47. lines[#lines + 1] = m
  48. until m == nil
  49.  
  50. file.close()
  51.  
  52. i = 1
  53. while true do
  54. if lines[i] == nil then break end
  55. text = {}
  56. for w in string.gmatch(lines[i], "%S+") do
  57. text[#text + 1] = w
  58. end
  59.  
  60. if string.lower(text[1]) == "left" or string.lower(text[1]) == "right" or string.lower(text[1]) == "front" or string.lower(text[1]) == "back" or string.lower(text[1]) == "top" or string.lower(text[1]) == "bottom" then
  61.     if string.lower(text[2]) == "on" then
  62.         rs.setOutput(string.lower(text[1]), true)
  63.     elseif string.lower(text[2]) == "off" then
  64.         rs.setOutput(string.lower(text[1]), false)
  65.     else
  66.         print("Syntax Error: Line #" .. i .. " Unknown Subcommand for SIDE: " .. text[2])
  67.         return
  68.     end
  69.  
  70. i = i + 1
  71. elseif string.lower(text[1]) == "wait" then
  72.     if tonumber(text[2]) ~= nil then
  73.         sleep( tonumber(text[2]) )
  74.     elseif string.lower(text[2]) == "left" or string.lower(text[2]) == "right" or string.lower(text[2]) == "front" or string.lower(text[2]) == "back" or string.lower(text[2]) == "top" or string.lower(text[2]) == "bottom" then
  75.         while rs.getInput(string.lower(text[2])) == false do
  76.             sleep(0.05)
  77.         end
  78.     else
  79.         print("Syntax Error: Line #" .. i .. " Wrong argument for WAIT: " .. text[2])
  80.         return
  81.     end
  82. i = i + 1
  83. elseif string.lower(text[1]) == "compare" then
  84.     if text[2] == "input" then
  85.        
  86.     elseif text[3] == "input" then
  87.  
  88.     else
  89.    
  90.     end
  91. i = i + 1
  92. elseif string.lower(text[1]) == "goto" then
  93.     if tonumber(text[2]) ~= nil then
  94.         i = ( tonumber(text[2]) )
  95.     else
  96.         print("Syntax Error: Line #" .. i .. " Wrong argument for GOTO: " .. text[2])
  97.         return
  98.     end
  99. elseif string.lower(text[1]) == "" then
  100. i = i + 1
  101. elseif string.lower(text[1]) == "" then
  102. i = i + 1
  103. elseif string.lower(text[1]) == "" then
  104. i = i + 1
  105. elseif string.lower(text[1]) == "" then
  106. i = i + 1
  107.  
  108. else
  109. print("Syntax Error: Line #" .. i .. " Unknown Command: " .. text[1])
  110. return
  111. end
  112.  
  113.  
  114.  
  115.  
  116.  
  117. end
Advertisement
Add Comment
Please, Sign In to add comment