Savage_Me55iah

CODE_EMBED_EXPERIMENTAL

Dec 25th, 2016
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 79.03 KB | None | 0 0
  1. --Script by Savage_Me55iah of CraftAU.com.au and Nuqube.co--
  2. local scriptName, version, pastebinCode = "CODE_EMBED_EXPERIMENTAL", "v0.4", "5y35NCBX"
  3.  
  4. --Other Savage_Me55iah scripts @ http://pastebin.com/u/Savage_Me55iah
  5.  
  6. --INSTRUCTIONS ON USE--
  7. --Instruction video on http://youtube.com/savagemessiah5
  8.  
  9. --Contact Savage_Me55iah @ CraftAU.com.au or Nuqube.co or http://www.computercraft.info/forums2/ with suggestions/fixes/bugs
  10.  
  11. -- CHANGELOG --
  12. --V1.0 -
  13. -- Limited monitors supported
  14.  
  15. -- SETUP --
  16.  
  17. local debugLevel, debugTime = 0, 0.1
  18. local tArgs = {...}
  19. local update_request = tArgs[1]
  20. local logTable = {}
  21.  
  22. if (os.getComputerLabel() or true) then os.setComputerLabel(scriptName.."-"..math.random(1000, 9999)) end
  23.  
  24. local consoleWriteF = nil
  25. function console(param_text, param_logLevel)
  26.     local result, text, logLevel, functionName = false, param_text, param_logLevel or 0, "console"
  27.     if tostring(consoleWriteF) ~= "nil" then
  28.         result = consoleWriteF(text, logLevel)
  29.     else
  30.         table.insert(logTable, {["text"] = text, ["logLevel"] = logLevel, ["time"] = os.day() .. ": " .. textutils.formatTime(os.time(), true)})
  31.         print(text)
  32.         result = true
  33.     end
  34.     if debugLevel >= 1 then sleep(debugTime) end
  35.     return result
  36. end
  37.  
  38. -----------------------------------------------------------------------------------------------------------
  39. -- UPDATER SETUP -- EMBEDED --
  40. -----------------------------------------------------------------------------------------------------------
  41.  
  42. function update(script_name, pastebincode)
  43.     console("UPDATING") shell.run("pastebin get "..pastebincode.." update")
  44.     if fs.exists("update") then
  45.         fs.delete(script_name) fs.copy("update", script_name) fs.delete("update") console("UPDATE SUCCESS")
  46.     else
  47.         console("UPDATE FAILED")
  48.     end
  49.     sleep(2) os.reboot()
  50. end
  51.  
  52. if tostring(update_request) == "update" then update(shell.getRunningProgram(), pastebinCode) end
  53. console("marker - update setup complete")
  54.  
  55. -----------------------------------------------------------------------------------------------------------
  56. -- DUMMY FUNCTIONS -- EMBEDED -- THIS ALLOWS ME TO WRITE MY FUNCTIONS EVERYWHERE, NOT JUST IN LINEAR ORDER
  57. -----------------------------------------------------------------------------------------------------------
  58.  
  59. -- VARIABLE MANIPULATION FUNCTIONS
  60.     function Debug(...) local results = false if tostring(DebugF) ~= "nil" then results = DebugF(...) else console("error: dummy function fail: Debug") end return results end
  61.     function insertBS(...) local results = false if tostring(insertBSF) ~= "nil" then results = insertBSF(...) else console("error: dummy function fail: insertBS") end return results end
  62.     function value(...) local results = false if tostring(valueF) ~= "nil" then results = valueF(...) else console("error: dummy function fail: value") end return results end
  63.     function booleanCheck(...) local results = false if tostring(booleanCheckF) ~= "nil" then results = booleanCheckF(...) else console("error: dummy function fail: booleanCheck") end return results end
  64.     function massAndBooleanCheck(...) local results = false if tostring(massAndBooleanCheckF) ~= "nil" then results = massAndBooleanCheckF(...) else console("error: dummy function fail: massAndBooleanCheck") end return results end
  65.     function massOrBooleanCheck(...) local results = false if tostring(massOrBooleanCheckF) ~= "nil" then results = massOrBooleanCheckF(...) else console("error: dummy function fail: massOrBooleanCheck") end return results end
  66.     function multiOrCompare(...) local results = false if tostring(multiOrCompareF) ~= "nil" then results = multiOrCompareF(...) else console("error: dummy function fail: multiOrCompare") end return results end
  67.     function multiAndCompare(...) local results = false if tostring(multiAndCompareF) ~= "nil" then results = multiAndCompareF(...) else console("error: dummy function fail: multiAndCompare") end return results end
  68.     function stringCombine(...) local results = false if tostring(stringCombineF) ~= "nil" then results = stringCombineF(...) else console("error: dummy function fail: stringCombine") end return results end
  69.     function variableCheck(...) local results = false if tostring(variableCheckF) ~= "nil" then results = variableCheckF(...) else console("error: dummy function fail: variableCheck") end return results end
  70.     function quickChoice(...) local results = false if tostring(quickChoiceF) ~= "nil" then results = quickChoiceF(...) else console("error: dummy function fail: quickChoice") end return results end
  71.     function tolerance(...) local results = false if tostring(toleranceF) ~= "nil" then results = toleranceF(...) else console("error: dummy function fail: tolerance") end return results end
  72.  
  73. -- PERIPHERAL/WINDOW MANIPULATION FUNCTIONS
  74.     function peripheralFindType(...) local results = false if tostring(peripheralFindTypeF) ~= "nil" then results = peripheralFindTypeF(...) else console("error: dummy function fail: peripheralFindType") end return results end
  75.     function monitorSetScale(...) local results = false if tostring(monitorSetScaleF) ~= "nil" then results = monitorSetScaleF(...) else console("error: dummy function fail: monitorSetScale") end return results end
  76.     function monitorDetect(...) local results = false if tostring(monitorDetectF) ~= "nil" then results = monitorDetectF(...) else console("error: dummy function fail: monitorDetect") end return results end
  77.     function stdWindowsCreate(...) local results = false if tostring(stdWindowsCreateF) ~= "nil" then results = stdWindowsCreateF(...) else console("error: dummy function fail: stdWindowsCreate") end return results end
  78.     function addStdWindow(...) local results = false if tostring(addStdWindowF) ~= "nil" then results = addStdWindowF(...) else console("error: dummy function fail: addStdWindow") end return results end
  79.     function switchWindow(...) local results = false if tostring(switchWindowF) ~= "nil" then results = switchWindowF(...) else console("error: dummy function fail: switchWindow") end return results end
  80.     function activeWindow(...) local results = false if tostring(activeWindowF) ~= "nil" then results = activeWindowF(...) else console("error: dummy function fail: activeWindow") end return results end
  81.     function resizeWindow(...) local results = false if tostring(resizeWindowF) ~= "nil" then results = resizeWindowF(...) else console("error: dummy function fail: resizeWindow") end return results end
  82.     function clearWindow(...) local results = false if tostring(clearWindowF) ~= "nil" then results = clearWindowF(...) else console("error: dummy function fail: clearWindow") end return results end
  83.  
  84. --
  85.     function selectColor(...) local results = false if tostring(selectColorF) ~= "nil" then results = selectColorF(...) else console("error: dummy function fail: selectColor") end return results end
  86.     function screenWrite(...) local results = false if tostring(screenWriteF) ~= "nil" then results = screenWriteF(...) else console("error: dummy function fail: screenWrite") end return results end
  87.     function windowWrite(...) local results = false if tostring(windowWriteF) ~= "nil" then results = windowWriteF(...) else console("error: dummy function fail: windowWrite") end return results end
  88.     function backgroundColor(...) local results = false if tostring(backgroundColorF) ~= "nil" then results = backgroundColorF(...) else console("error: dummy function fail: backgroundColor") end return results end
  89.  
  90. -- TABLE MANIPULATION FUNCTIONS
  91.     function loadTable(...) local results = false if tostring(loadTableF) ~= "nil" then results = loadTableF(...) else console("error: dummy function fail: loadTable") end return results end
  92.     function saveTable(...) local results = false if tostring(saveTableF) ~= "nil" then results = saveTableF(...) else console("error: dummy function fail: saveTable") end return results end
  93.  
  94. -- LOGGING FUNCTIONS
  95.     function logSetup(...) local results = false if tostring(logSetupF) ~= "nil" then results = logSetupF(...) else console("error: dummy function fail: logSetup") end return results end
  96.  
  97. -- BUTTON MANIPULATION FUNCTIONS
  98.     function generateButton(...) local results = false if tostring(generateButtonF) ~= "nil" then results = generateButtonF(...) else console("error: dummy function fail: generateButton") end return results end
  99.     function stdPulse(...) local results = false if tostring(stdPulseF) ~= "nil" then results = stdPulseF(...) else console("error: dummy function fail: stdPulse") end return results end
  100.     function stdToggle(...) local results = false if tostring(stdToggleF) ~= "nil" then results = stdToggleF(...) else console("error: dummy function fail: stdToggle") end return results end
  101.     function monitorToggle(...) local results = false if tostring(monitorToggleF) ~= "nil" then results = monitorToggleF(...) else console("error: dummy function fail: monitorToggle") end return results end
  102.     function dataChange(...) local results = false if tostring(dataChangeF) ~= "nil" then results = dataChangeF(...) else console("error: dummy function fail: dataChange") end return results end
  103.     function addButton(...) local results = false if tostring(addButtonF) ~= "nil" then results = addButtonF(...) else console("error: dummy function fail: addButton") end return results end
  104.     function monitorListApply(...) local results = false if tostring(monitorListApplyF) ~= "nil" then results = monitorListApplyF(...) else console("error: dummy function fail: monitorListApply") end return results end
  105.     function addMonitorListButtons(...) local results = false if tostring(addMonitorListButtonsF) ~= "nil" then results = addMonitorListButtonsF(...) else console("error: dummy function fail: addMonitorListButtons") end return results end
  106.     function generateWindowButtons(...) local results = false if tostring(generateWindowButtonsF) ~= "nil" then results = generateWindowButtonsF(...) else console("error: dummy function fail: generateWindowButtons") end return results end
  107.     function generateAllButtons(...) local results = false if tostring(generateAllButtonsF) ~= "nil" then results = generateAllButtonsF(...) else console("error: dummy function fail: generateAllButtons") end return results end
  108.     function updateButton(...) local results = false if tostring(updateButtonF) ~= "nil" then results = updateButtonF(...) else console("error: dummy function fail: updateButton") end return results end
  109.     function startupScript(...) local results = false if tostring(startupScriptF) ~= "nil" then results = startupScriptF(...) else console("error: dummy function fail: startupScript") end return results end
  110.     function monitorListWindow(...) local results = false if tostring(monitorListWindowF) ~= "nil" then results = monitorListWindowF(...) else console("error: dummy function fail: monitorListWindow") end return results end
  111.     function restart(...) local results = false if tostring(restartF) ~= "nil" then results = restartF(...) else console("error: dummy function fail: restart") end return results end
  112.     function terminate(...) local results = false if tostring(terminateF) ~= "nil" then results = terminateF(...) else console("error: dummy function fail: terminate") end return results end
  113.     function stdButtons(...) local results = false if tostring(stdButtonsF) ~= "nil" then results = stdButtonsF(...) else console("error: dummy function fail: stdButtons") end return results end
  114.     function topBarScroll(...) local results = false if tostring(topBarScrollF) ~= "nil" then results = topBarScrollF(...) else console("error: dummy function fail: topBarScroll") end return results end
  115.     function topBarChange(...) local results = false if tostring(topBarChangeF) ~= "nil" then results = topBarChangeF(...) else console("error: dummy function fail: topBarChange") end return results end
  116.     function topBarButtons(...) local results = false if tostring(topBarButtonsF) ~= "nil" then results = topBarButtonsF(...) else console("error: dummy function fail: topBarButtons") end return results end
  117.     function buttonScan(...) local results = false if tostring(buttonScanF) ~= "nil" then results = buttonScanF(...) else console("error: dummy function fail: buttonScan") end return results end
  118.  
  119. --
  120.     function eventFilter(...) local results = false if tostring(eventFilterF) ~= "nil" then results = eventFilterF(...) else console("error: dummy function fail: eventFilter") end return results end
  121.     function insertWindow(...) local results = false if tostring(insertWindowF) ~= "nil" then results = insertWindowF(...) else console("error: dummy function fail: insertWindow") end return results end
  122.     function messageWindow(...) local results = false if tostring(messageWindowF) ~= "nil" then results = messageWindowF(...) else console("error: dummy function fail: messageWindow") end return results end
  123.     function peripheralListRegisterSingle(...) local results = false if tostring(peripheralListRegisterSingleF) ~= "nil" then results = peripheralListRegisterSingleF(...) else console("error: dummy function fail: peripheralListRegisterSingle") end return results end
  124.     function peripheralListRegisterMulti(...) local results = false if tostring(peripheralListRegisterMultiF) ~= "nil" then results = peripheralListRegisterMultiF(...) else console("error: dummy function fail: peripheralListRegisterMulti") end return results end
  125.     function peripheralListAdd(...) local results = false if tostring(peripheralListAddF) ~= "nil" then results = peripheralListAddF(...) else console("error: dummy function fail: peripheralListAdd") end return results end
  126.     function peripheralFind(...) local results = false if tostring(peripheralFindF) ~= "nil" then results = peripheralFindF(...) else console("error: dummy function fail: peripheralFind") end return results end
  127.    
  128.    
  129.  
  130. console("marker - dummy functions setup complete")
  131.  
  132. -----------------------------------------------------------------------------------------------------------
  133. -- PRELIMENARY FUNCTIONS -- EMBEDED --
  134. -----------------------------------------------------------------------------------------------------------
  135.  
  136. function DebugF(lvl, ...) if (debugLevel == 2 and lvl ~= "basic") or debugLevel > 2 then console(...) end return true end
  137.  
  138. -- BACKSLASH WAS MESSING WITH MY SCRIPT EDITOR
  139. function insertBSF()
  140.     local result = "\\"
  141.     return result
  142. end
  143.  
  144. -- value structure
  145. -- example = {["value"], ["type"], ["nil"], ["incr"], ["max"], ["min"], ["result"]}
  146.  
  147. function valueF(param_prev, param_value, param_incr, param_max, param_min)
  148.     local result, functionName = {false, {}}, "valueF"
  149.     Debug("basic", "debug: "..functionName)
  150.     result[2] = quickChoice(multiAndCompare(false, booleanCheck(param_prev)[1], booleanCheck(param_prev)[2])[2], {["value"] = false, ["type"] = "nil", ["nil"] = true, ["increment"] = "nil", ["max"] = "nil", ["min"] = "nil", ["result"] = false}, param_prev)[2]
  151.     if booleanCheck(result[2])[1] then
  152.         result[2]["value"] = booleanCheck(param_value)[2]
  153.         result[2]["type"] = type(param_value)
  154.         result[2]["nil"] = false
  155.         result[2]["incr"] = param_incr or result[2]["incr"] or "nil"
  156.         result[2]["max"] = param_max or result[2]["max"] or "nil"
  157.         result[2]["min"] = param_min or result[2]["min"] or "nil"
  158.         result[1], result[2]["result"] = true, true
  159.     end
  160.     Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
  161.     return result
  162. end
  163.  
  164. function booleanCheckF(params)
  165.     local result, functionName = {[1] = false, [2] = nil}, "booleanCheckF"
  166.     if tostring(params) ~= "nil" then
  167.         result = {true, params}
  168.     else
  169.         result = {false, false}
  170.     end
  171.     return result
  172. end
  173.  
  174. function massAndBooleanCheckF(...)
  175.     local list, result, functionName = {...}, {false, true}, "massAndBooleanCheckF"
  176.     Debug("basic", "debug: "..functionName)
  177.     for a,b in pairs(list) do result[2] = quickChoice(b, result[2], false)[2] end result[1] = true
  178.     Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
  179.     return result
  180. end
  181.  
  182. function massOrBooleanCheckF(...)
  183.     local list, result, functionName = {...}, {false, false}, "massOrBooleanCheckF"
  184.     Debug("basic", "debug: "..functionName)
  185.     for a,b in pairs(list) do result[2] = quickChoice(b, true, result[2])[2] end result[1] = true
  186.     Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
  187.     return result
  188. end
  189.  
  190. function multiOrCompareF(param_arg, ...)
  191.     local list, result, functionName = {...}, {false, false}, "multiOrCompareF"
  192.     Debug("basic", "debug: "..functionName)
  193.     for a,b in pairs(list) do result[2] = quickChoice((booleanCheck(param_arg)[2] == booleanCheck(b)[2]), true, result[2])[2] end
  194.     result[1] = true
  195.     Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
  196.     return result
  197. end
  198.  
  199. function multiAndCompareF(param_arg, ...)
  200.     local list, result, functionName = {...}, {false, true}, "multiAndCompareF"
  201.     Debug("basic", "debug: "..functionName)
  202.     for a,b in pairs(list) do result[2] = quickChoice((booleanCheck(param_arg)[2] == booleanCheck(b)[2]), result[2], false)[2] end
  203.     result[1] = true
  204.     Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
  205.     return result
  206. end
  207.  
  208. function stringCombineF(param_space, ...)
  209.     local tempList, stringList, result, functionName = {...}, {}, {false, nil}, "stringCombineF"
  210.     Debug("basic", "debug: "..functionName)
  211.     if booleanCheck(type(param_space))[2] == "boolean" then
  212.         for a,b in pairs(tempList) do
  213.             if booleanCheck(type(b))[2] == "table" then
  214.                 for c,d in pairs(tempList[a]) do table.insert(stringList, d) end
  215.             else
  216.                 if booleanCheck(b)[1] then table.insert(stringList, tostring(b)) end
  217.             end
  218.         end
  219.         for a,b in pairs(stringList) do
  220.             if type(b) ~= "table" then
  221.                 if param_space then
  222.                     result[2] = quickChoice(booleanCheck(result[2])[1], tostring(result[2]).." "..tostring(b), tostring(b))[2]
  223.                 else
  224.                     result[2] = quickChoice(booleanCheck(result[2])[1], tostring(result[2])..tostring(b), tostring(b))[2]
  225.                 end
  226.             end
  227.         end
  228.         result[1] = true
  229.     else
  230.         console("error: variable in func "..functionName.." incorrect, expected: table")
  231.     end
  232.     Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
  233.     return result
  234. end
  235.  
  236. function variableCheckF(param_functionName, param_type, param_variable)
  237.     local result, errorMsg, variableMsg, functionName, tempTable = {false, false}, ":", ":", "variableCheckF", {}
  238.     Debug("basic", "debug: "..functionName)
  239.     if multiAndCompare("table", type(param_type), type(param_variable))[2] then
  240.         for a,b in pairs(param_variable) do
  241.             tempTable[a], errorMsg = false, ":"
  242.             for c,d in pairs(param_type) do
  243.                 if massAndBooleanCheck(booleanCheck(b)[1], booleanCheck(d)[1])[2] then
  244.                     tempTable[a], variableMsg, errorMsg = quickChoice((d == type(b)), true, tempTable[a])[2], stringCombine(true, {variableMsg, b})[2], stringCombine(true, {errorMsg, d})[2]
  245.                 end
  246.             end
  247.         end
  248.         result[2] = true
  249.         for a,b in pairs(tempTable) do result = {true, quickChoice(tempTable[a], tempTable[a], false)[2]} end
  250.     else
  251.         console(stringCombine(true, "error: variable in func", functionName, "incorrect, expected: table")[2])
  252.     end
  253.     if not result[2] then console(stringCombine(true, "error: variable in func", param_functionName, "incorrect, expected:", errorMsg, "got", variableMsg)[2]) end
  254.     Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
  255.     return result
  256. end
  257.  
  258. function quickChoiceF(param_boolean, param_true, param_false)
  259.     local result, functionName = {false, false}, "quickChoiceF"
  260.     Debug("basic", "debug: "..functionName)
  261.     if booleanCheck(type(param_boolean))[2] == "boolean" then
  262.         if booleanCheck(param_boolean)[2] == true then result = {true, param_true} else result = {true, param_false} end
  263.     else
  264.         result = {false, param_false}
  265.     end
  266.     Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
  267.     return result
  268. end
  269.  
  270. function toleranceF(param_target, param_value, param_tolerancePositive, param_toleranceNegative)
  271.     local result, functionName = {false, false}, "toleranceF"
  272.     Debug("basic", "debug: "..functionName)
  273.     if variableCheck(functionName, {"number"}, {param_target, param_value})[2] then
  274.         local tolerancePositive, toleranceNegative = param_tolerancePositive or 0, param_toleranceNegative or 0
  275.         tolerancePositive, toleranceNegative = param_target + tolerancePositive, param_target + toleranceNegative
  276.         result = {true, quickChoice(massAndBooleanCheck((param_value <= tolerancePositive), (param_value >= toleranceNegative))[2], true, false)[2]}
  277.     end
  278.     Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
  279.     return result
  280. end
  281.  
  282. --  modems = peripheralFindF("method", "modem", "wireless") .. returns a table of all peripherals of the same type --
  283. function peripheralFindF(param_mode, param_variable, modem_type)
  284.     local functionName, peripheralList, result, modem_type = "peripheralFindF", peripheral.getNames() or false, {false, {}}, modem_type or false
  285.     Debug("basic", "debug: "..functionName)
  286.     if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_mode})[2], variableCheck(functionName, {"table"}, {param_variable})[2], peripheralList ~= false)[2] then
  287.         console(stringCombine(true, "finding peripherals:-", param_mode, param_variable, modem_type)[2])
  288.         for a,b in pairs(peripheralList) do
  289.        
  290.             if param_mode == "type" then
  291.                 local testType = peripheral.getType(b)
  292.                 for c,d in pairs(param_variable) do
  293.                     if testType == tostring(d) then
  294.                         if tostring(modem_type) == "false" then
  295.                             table.insert(result[2], b) result[1] = true
  296.                         else
  297.                             local Peripheral = peripheral.wrap(b)
  298.                             local wireless = booleanCheck(Peripheral.isWireless())[2]
  299.                             if modem_type == "wireless" and wireless then table.insert(result[2], b) result[1] = true
  300.                             elseif modem_type == "modem" and not wireless then table.insert(result[2], b) result[1] = true
  301.                 end end end end
  302.                
  303.             elseif param_mode == "method" then
  304.                 local tempList, methodTest = peripheral.getMethods(b), true
  305.                 for c,d in pairs(tempList) do
  306.                     methodTest = true
  307.                     for e,f in pairs(param_variable) do
  308.                         methodTest = quickChoice(d == f, methodTest, false)[2]
  309.                     end
  310.                     if methodTest then table.insert(result[2], b) result[1] = true end
  311.             end end
  312.     end end
  313.     if not result[1] then result[2] = false console(stringCombine(true, "error:- cannot find peripheral:-", param_mode, param_variable)[2], 1) else console("peripheral find success") end
  314.     Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
  315.     return result
  316. end
  317.  
  318. console("marker - preliminary functions setup complete")
  319.  
  320. -----------------------------------------------------------------------------------------------------------
  321. -- SAVE/LOAD FUNCTIONS -- EMBEDED --
  322. -----------------------------------------------------------------------------------------------------------
  323.  
  324. --  users = loadTable("users", "datastore") .. returns table from an external/previously saved table, directory not required --
  325. function loadTableF(param_tableName, param_directory)
  326.     local location, result, functionName = param_tableName, {false, false}, "loadTableF"
  327.     Debug("secondary", "debug: "..functionName)
  328.     if variableCheck(functionName, {"string"}, {param_tableName})[2] then
  329.         if booleanCheck(param_directory)[1] then
  330.             if variableCheck(functionName, {"string"}, {param_directory})[2] then
  331.                 location = quickChoice(booleanCheck(fs.isDir(param_directory))[2], param_directory..insertBS()..param_tableName, location)[2]
  332.             end
  333.         end
  334.         if fs.exists(location) then
  335.             local filehandler = fs.open(location, 'r')
  336.             result = {true, textutils.unserialize(filehandler.readAll())}
  337.             filehandler.close()
  338.         end
  339.         if not result[1] then console(stringCombine(true, "error:", location)[2]) end
  340.     end
  341.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  342.     return result
  343. end
  344.  
  345. --  saveTable("users", users, "datastore") .. returns boolean, saves table into a file, directory not required --
  346. function saveTableF(param_tableName, param_table, param_directory)
  347.     local location, result, functionName = param_tableName, {false, false}, "saveTableF"
  348.     Debug("secondary", "debug: "..functionName)
  349.     if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_tableName})[2], variableCheck(functionName, {"table"}, {param_table})[2])[2] then
  350.         if booleanCheck(param_directory)[1] ~= false then
  351.             if variableCheck(functionName, {"string"}, {param_directory})[2] then
  352.                 if booleanCheck(fs.isDir(param_directory))[2] ~= true then
  353.                     fs.makeDir(tostring(param_directory))
  354.                 end
  355.                 location = param_directory..insertBS()..param_tableName
  356.             end
  357.         end
  358.         local filehandler = fs.open(location, 'w')
  359.         result = {true, filehandler.write(textutils.serialize(param_table))}
  360.         filehandler.close()
  361.         if not result[1] then console(stringCombine(true, "error:", location)[2]) end
  362.     end
  363.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  364.     return result
  365. end
  366.  
  367. console("marker - load/save setup complete")
  368.  
  369. -----------------------------------------------------------------------------------------------------------
  370. -- WINDOWS SETUP -- EMBEDED --
  371. -----------------------------------------------------------------------------------------------------------
  372.  
  373. local termX, termY = term.getSize()
  374.  
  375. varList = {
  376.     ["monitorList"] = {},
  377.     ["stdWindows"] = {},
  378.     ["currentWindow"] = {["term"] = "console", ["monitor"] = "console"},
  379.     ["buttons"] = {},
  380.     ["stdWindowsData"] = {}
  381. }
  382.  
  383. function monitorSetScaleF()
  384.     local result, functionName = {false, nil}, "monitorSetScaleF"
  385.     Debug("secondary", "debug: "..functionName)
  386.     for a,b in pairs(varList["monitorList"]) do
  387.         if varList["monitorList"][a]["active"] then
  388.             console("setting monitor scales")
  389.             local tempMonitor, scale = peripheral.wrap(varList["monitorList"][a]["name"]), 5
  390.             tempMonitor.setTextScale(scale)
  391.             local monX, monY = tempMonitor.getSize()
  392.             while massOrBooleanCheck(tolerance(termX, monX, -1, -termX)[2], tolerance(termY, monY, -1, -termY)[2])[2] and scale ~= 0.5 do
  393.                 scale = scale - 0.2
  394.                 tempMonitor.setTextScale(scale)
  395.                 monX, monY = tempMonitor.getSize()
  396.                 result[1] = true
  397.             end
  398.             console(stringCombine(true, "completed monitor scale:",b,scale)[2])
  399.         end
  400.     end
  401.     console("completed all monitor scaling")
  402.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  403.     return result
  404. end
  405.  
  406. function monitorDetectF()
  407.     local tempListA, result, functionName = quickChoice(fs.exists("dataStore"..insertBS().."monitorList"), loadTable("monitorList", "dataStore")[2], varList["monitorList"])[2], {false, nil}, "monitorDetectF"
  408.     Debug("secondary", "debug: "..functionName)
  409.     varList["monitorList"] = {}
  410.     local tempListB = peripheralFind("type", {"monitor"})
  411.     if tempListB[1] then
  412.         for a,b in pairs(tempListB[2]) do
  413.             varList["monitorList"][a] = {["name"] = b, ["active"] = false}
  414.         end
  415.         if booleanCheck(tempListA[1])[1] then
  416.             for a,b in pairs(tempListA) do
  417.                 for c,d in pairs(varList["monitorList"]) do
  418.                     varList["monitorList"][c]["active"] = quickChoice((varList["monitorList"][c]["name"] == tempListA[a]["name"]), tempListA[a]["active"], varList["monitorList"][c]["active"])[2]
  419.     end end end end
  420.     monitorSetScale()
  421.     saveTable("monitorList", varList["monitorList"], "dataStore")
  422.     varList["monitorList"]["terminal"] = {["name"] = term.native(), ["active"] = true}
  423.     result[1] = true
  424.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  425.     return result
  426. end
  427.  
  428. function stdWindowsCreateF()
  429.     local currentTerm, result, functionName = term.current(), {false, nil}, "stdWindowsCreateF"
  430.     Debug("secondary", "debug: "..functionName)
  431.     term.redirect(term.native())
  432.     console("creating windows")
  433.     for c,d in pairs(varList["stdWindowsData"]) do
  434.         for a,b in pairs(varList["monitorList"]) do
  435.             if varList["monitorList"][a]["active"] then
  436.                 local TLX, TLY, XL, YL = varList["stdWindowsData"][c]["TLX"], varList["stdWindowsData"][c]["TLY"], varList["stdWindowsData"][c]["XL"], varList["stdWindowsData"][c]["YL"]
  437.                 varList["stdWindows"][c] = quickChoice(booleanCheck(varList["stdWindows"][c])[1], booleanCheck(varList["stdWindows"][c])[2], {})[2]
  438.                 if varList["monitorList"][a]["name"] ~= term.native() then
  439.                     if booleanCheck(varList["stdWindows"][c][varList["monitorList"][a]["name"]])[1] == false then
  440.                         local tempWrap = peripheral.wrap(varList["monitorList"][a]["name"])
  441.                         varList["stdWindows"][c][varList["monitorList"][a]["name"]] = {}
  442.                         varList["stdWindows"][c][varList["monitorList"][a]["name"]][1] = window.create(tempWrap, TLX, TLY, XL, YL, false)
  443.                         varList["stdWindows"][c][varList["monitorList"][a]["name"]][2] = window.create(varList["stdWindows"][c][varList["monitorList"][a]["name"]][1], (1 - (TLX - 1)), (1 - (TLY - 1)), termX, termY, true)
  444.                         result[1] = true
  445.                     end
  446.                 else
  447.                     if booleanCheck(varList["stdWindows"][c]["term"])[1] == false then
  448.                         varList["stdWindows"][c]["term"] = {}
  449.                         varList["stdWindows"][c]["term"][1] = window.create(term.native(), TLX, TLY, XL, YL, false)
  450.                         varList["stdWindows"][c]["term"][2] = window.create(varList["stdWindows"][c]["term"][1], (1 - (TLX - 1)), (1 - (TLY - 1)), termX, termY, true)
  451.                         result[1] = true
  452.                     end
  453.                 end
  454.             else
  455.                 if booleanCheck(varList["stdWindows"][c])[1] then if booleanCheck(varList["stdWindows"][c][varList["monitorList"][a]["name"]])[1] then varList["stdWindows"][c][varList["monitorList"][a]["name"]] = nil end end
  456.             end
  457.         end
  458.         activeWindow("both", c, false)
  459.     console(stringCombine(true, "creating window", c, "completed")[2])
  460.     term.redirect(currentTerm)
  461.     end
  462.     console("creating windows completed")
  463.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  464.     return result
  465. end
  466.  
  467. function addStdWindowF(param_name, param_TLX, param_TLY, param_XL, param_YL, param_topBar)
  468.     local result, functionName = {false, nil}, "addStdWindowF"
  469.     Debug("secondary", "debug: "..functionName)
  470.     if massAndBooleanCheck(variableCheck("addStdWindowF", {"string"}, {param_name})[2], variableCheck("addStdWindowF", {"number"}, {param_TLX, param_TLY, param_XL, param_YL})[2], variableCheck("addStdWindowF", {"boolean"}, {param_topBar})[2])[2] then
  471.         if booleanCheck(varList["stdWindowsData"][param_name])[1] == false then
  472.             varList["stdWindowsData"][param_name] = {["TLX"] = param_TLX, ["TLY"] = param_TLY, ["XL"] = param_XL, ["YL"] = param_YL, ["topBar"] = param_topBar}
  473.             console("adding std window: "..param_name)
  474.             result[1] = true
  475.         end
  476.     end
  477.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  478.     return result
  479. end
  480.  
  481. function activeWindowF(param_screen, param_window, param_boolean)
  482.     local result, functionName = {false, nil}, "activeWindowF"
  483.     Debug("secondary", "debug: "..functionName)
  484.     if variableCheck(functionName, {"string"}, {param_screen, param_window})[2] then
  485.         local screen = quickChoice(multiOrCompare(param_screen, "monitor", "monitor_touch")[2], "monitor", "both")[2]
  486.         screen = quickChoice(multiOrCompare(param_screen, "term", "mouse_click")[2], "term", screen)[2]
  487.         if booleanCheck(varList["stdWindows"][param_window])[1] then
  488.             local tempTable = varList["stdWindows"][param_window]
  489.             if screen == "both" then
  490.                 for a,b in pairs(tempTable) do
  491.                     local posX, posY = tempTable[a][1].getPosition()
  492.                     if massAndBooleanCheck((param_boolean == true), (posX < 0))[2] then
  493.                         resizeWindow(a, param_window, (posX + termX), posY)
  494.                     elseif massAndBooleanCheck((param_boolean == false), (posX > 0))[2] then
  495.                         resizeWindow(a, param_window, (posX - termX), posY)
  496.                     end
  497.                     tempTable[a][1].setVisible(param_boolean) tempTable[a][2].setVisible(param_boolean)
  498.                 end
  499.             elseif screen == "term" then
  500.                 local posX, posY = tempTable["term"][1].getPosition()
  501.                 if massAndBooleanCheck((param_boolean == true), (posX < 0))[2] then
  502.                     resizeWindow("term", param_window, (posX + termX), posY)
  503.                 elseif massAndBooleanCheck((param_boolean == false), (posX >= 0))[2] then
  504.                     resizeWindow("term", param_window, (posX - termX), posY)
  505.                 end
  506.                 tempTable["term"][1].setVisible(param_boolean) tempTable["term"][2].setVisible(param_boolean)
  507.             elseif screen == "monitor" then
  508.                 for a,b in pairs(tempTable) do
  509.                     if a ~= "term" then
  510.                         local posX, posY = tempTable[a][1].getPosition()
  511.                         if massAndBooleanCheck((param_boolean == true), (posX < 0))[2] then
  512.                             resizeWindow(a, param_window, (posX + termX), posY)
  513.                         elseif massAndBooleanCheck((param_boolean == false), (posX > 0))[2] then
  514.                             resizeWindow(a, param_window, (posX - termX), posY)
  515.                         end
  516.                         tempTable[a][1].setVisible(param_boolean) tempTable[a][2].setVisible(param_boolean)
  517.     end end end end end
  518.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  519.     return result
  520. end
  521.  
  522. function switchWindowF(param_screen, param_window)
  523.     local result, functionName, screen = {true, nil}, "switchWindowF", param_screen
  524.     Debug("secondary", "debug: "..functionName)
  525.     if variableCheck(functionName, {"string"}, {screen, param_window})[2] then
  526.         screen = quickChoice(multiOrCompare(param_screen, "monitor", "monitor_touch")[2], "monitor", "both")[2]
  527.         screen = quickChoice(multiOrCompare(param_screen, "term", "mouse_click")[2], "term", screen)[2]
  528.         if booleanCheck(varList["stdWindows"][param_window])[1] then
  529.             local currWindow = nil
  530.             if screen == "both" then
  531.                 result[1] = quickChoice(activeWindow(screen, varList["currentWindow"]["monitor"], false)[2], result[1], false)[2]
  532.                 result[1] = quickChoice(activeWindow(screen, varList["currentWindow"]["term"], false)[2], result[1], false)[2]
  533.                 varList["currentWindow"] = {["term"] = param_window, ["monitor"] = param_window}
  534.                 result[1] = quickChoice(activeWindow(screen, varList["currentWindow"]["monitor"], true)[2], result[1], false)[2]
  535.                 result[1] = quickChoice(activeWindow(screen, varList["currentWindow"]["term"], true)[2], result[1], false)[2]
  536.             else
  537.                 result[1] = quickChoice(activeWindow(screen, varList["currentWindow"][screen], false)[2], result[1], false)[2]
  538.                 varList["currentWindow"][screen] = param_window
  539.                 result[1] = quickChoice(activeWindow(screen, varList["currentWindow"][screen], true)[2], result[1], false)[2]
  540.     end end end
  541.     if not result[1] then console(stringCombine(true, "error: failed to switch window:", screen, param_window)[2], 2) end
  542.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  543.     return result
  544. end
  545.  
  546. function resizeWindowF(param_screen, param_window, param_x, param_y, param_x2, param_y2)
  547.     local result, functionName = {false, false}, "resizeWindowF"
  548.     Debug("secondary", "debug: "..functionName)
  549.     if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_window, param_screen})[2], variableCheck(functionName, {"number"}, {param_x, param_y})[2])[2] then
  550.         local tempTable = varList["stdWindows"][param_window][param_screen]
  551.         local pos = {tempTable[2].getPosition()}
  552.         if variableCheck(functionName, {"number"}, {param_x2, param_y2})[2] then
  553.             tempTable[1].reposition(param_x, param_y, param_x2, param_y2)
  554.         else
  555.             tempTable[1].reposition(param_x, param_y)
  556.         end
  557.         tempTable[2].reposition(pos[1], pos[2]) result[1] = true
  558.         tempTable[1].redraw() tempTable[2].redraw()
  559.     end
  560.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  561.     return result
  562. end
  563.  
  564. function clearWindowF(param_window)
  565.     local result, functionName = {false, nil}, "clearWindowF"
  566.     Debug("secondary", "debug: "..functionName)
  567.     if variableCheck(functionName, {"string"}, {param_window})[2] then
  568.         for a,b in pairs(varList["stdWindows"][param_window]) do varList["stdWindows"][param_window][a][2].clear() end result[1] = true
  569.     end
  570.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  571.     return result
  572. end
  573.  
  574. addStdWindow("main", 1, 2, termX, termY - 1, true)
  575. addStdWindow("settings", 1, 2, termX, termY - 1, true)
  576. addStdWindow("control", 1, 2, termX, termY - 1, true)
  577. addStdWindow("console", 1, 2, termX, termY - 1, true)
  578. addStdWindow("monitorList", 1, 2, termX, termY - 1, false)
  579. addStdWindow("message", (termX / 2) - 10, (termX / 2) - 2, 20, 5, false)
  580. addStdWindow("scroll<", 1, 1, 3, 1, false, false)
  581. addStdWindow("topBar", 3, 1, (termX - 6), 1, false)
  582. addStdWindow("scroll>", (termX - 3), 1, 3, 1, false)
  583. monitorDetect()
  584. stdWindowsCreate()
  585. activeWindow("both", "console", true)
  586. activeWindow("both", "topBar", true)
  587. activeWindow("both", "scroll<", true)
  588. activeWindow("both", "scroll>", true)
  589. activeWindow("both", "console", true)
  590. console("marker - terminal windows setup complete")
  591.  
  592. -----------------------------------------------------------------------------------------------------------
  593. -- CONSOLE/LOGS SETUP -- EMBEDED --
  594. -----------------------------------------------------------------------------------------------------------
  595.  
  596. varList["logs"] = {["dir"] = "LOGS"}
  597. varList["logs"] = {
  598.     ["dir"] = varList["logs"]["dir"],
  599.     ["curr"] = varList["logs"]["dir"]..insertBS()..scriptName.."_CURRENT",
  600.     ["prev"] = varList["logs"]["dir"]..insertBS()..scriptName.."_PREVIOUS",
  601.     ["tableLoc"] = scriptName.."_LOGTABLE"
  602. }
  603. varList["logs"]["fileName"] = varList["logs"]["curr"]..insertBS()..scriptName.."_"..os.day().."_"..os.time()
  604.  
  605. function consoleWriteF(param_text, param_error)
  606.     local result, text, attachN, attachE, fileHandler, logLevel, functionName = {false, nil}, param_text:upper(), ">", "--", fs.open(varList["logs"]["fileName"], 'a'), "0", "consoleWriteF"
  607.     if booleanCheck(param_error)[1] then
  608.         if "number" == type(booleanCheck(param_error)[2]) then text, logLevel = attachE..param_error.." "..text, param_error else text = attachE..text end
  609.     else
  610.         text = attachN..text
  611.     end
  612.    
  613.     fileHandler.writeLine(text) fileHandler.close()
  614.     table.insert(logTable, {["text"] = text, ["logLevel"] = logLevel, ["time"] = os.day() .. ": " .. textutils.formatTime(os.time(), true)})
  615.     local filehandler = fs.open(varList["logs"]["tableLoc"], 'w')
  616.     filehandler.write(textutils.serialize(logTable))
  617.     filehandler.close()
  618.     local currentTerm = term.current()
  619.     for a,b in pairs(varList["stdWindows"]["console"]) do term.redirect(varList["stdWindows"]["console"][a][2]) print(text) end
  620.     term.redirect(currentTerm)
  621.     result[1] = true
  622.     return result
  623. end
  624.  
  625. function logSetupF()
  626.     local result, functionName = {false, nil}, "logSetupF"
  627.     Debug("secondary", "debug: "..functionName)
  628.     if fs.exists(varList["logs"]["dir"]) then
  629.         local list = fs.list(varList["logs"]["curr"])
  630.         if booleanCheck(list[1])[1] then
  631.             if fs.exists(varList["logs"]["prev"]..insertBS()..list[1]) then fs.delete(varList["logs"]["prev"]..insertBS()..list[1]) end
  632.             fs.copy(varList["logs"]["curr"]..insertBS()..list[1], varList["logs"]["prev"]..insertBS()..list[1])
  633.             fs.delete(varList["logs"]["curr"]..insertBS()..list[1])
  634.         end
  635.         result[1] = true
  636.     else
  637.         fs.makeDir(varList["logs"]["dir"]) fs.makeDir(varList["logs"]["curr"]) fs.makeDir(varList["logs"]["prev"])
  638.         result[1] = true
  639.     end
  640.     local fileHandler = fs.open(varList["logs"]["fileName"], 'a')
  641.     for a,b in pairs(logTable) do fileHandler.writeLine(logTable[a]["text"], logTable[a]["logLevel"]) end
  642.     fileHandler.close()
  643.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  644.     return result
  645. end
  646.  
  647. logSetup() 
  648.  
  649. console("marker - console/logs setup complete")
  650.  
  651. -----------------------------------------------------------------------------------------------------------
  652. -- WRITING FUNCTIONS -- EMBEDED --
  653. -----------------------------------------------------------------------------------------------------------
  654.  
  655. function selectColorF(param_screenLoc, param_screen, param_textColor, param_backColor)
  656.     local result, textColor, backColor, functionName = {false, nil}, param_textColor or colors.white, param_backColor or colors.black, "selectColorF"
  657.     local screen = quickChoice(param_screenLoc ~= "term", varList["stdWindows"][param_screenLoc][param_screen][2], term)[2]
  658.     Debug("secondary", "debug: "..functionName)
  659.     if not booleanCheck(screen.isColor())[2] then
  660.         backColor, textColor = quickChoice((backColor ~= colors.black), colors.white, colors.black)[2], quickChoice((backColor ~= colors.black), colors.black, colors.white)[2]
  661.     end
  662.     result[1] = massAndBooleanCheck(screen.setTextColor(textColor), screen.setBackgroundColor(backColor))[2]
  663.     result[2] = quickChoice(massOrBooleanCheck(screen.getBackgroundColor() ~= backColor, screen.getTextColor() ~= textColor)[2], false, true)[2]
  664.     if not result[1] then console(stringCombine(true, "error: failed setTextColor or setBackgroundColor:", param_textColor, param_backColor)[2], 2) end
  665.     if not result[2] then console(stringCombine(true, "error: failed to choose wanted colors")[2], 1) end
  666.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  667.     return result
  668. end
  669.  
  670. --  screenWrite(term.native(), "hello world":upper(), 5, 3, colors.red, colors.black) -- Writes to a single specified window
  671. function screenWriteF(param_screenLoc, param_screen, param_text, param_x, param_y, param_textColor, param_backColor)
  672.     local screen, result, functionName = varList["stdWindows"][param_screenLoc][param_screen][2], {false, nil}, "screenWriteF"
  673.     Debug("secondary", "debug: "..functionName)
  674.     if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_text})[2], variableCheck(functionName, {"number"}, {param_x, param_y})[2])[2] then
  675.         result[1] = true
  676.         screen.setCursorPos(param_x, param_y)
  677.         result[1] = quickChoice(selectColor(param_screenLoc, param_screen, param_textColor, param_backColor)[1], result[1], false)[2]
  678.         screen.write(param_text)
  679.         result[1] = quickChoice(selectColor(param_screenLoc, param_screen)[1], result[1], false)[2]
  680.         screen.redraw() varList["stdWindows"][param_screenLoc][param_screen][1].redraw()
  681.     end
  682.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  683.     return result
  684. end
  685.  
  686. --  windowWrite("console", "hello world":upper(), 5, 3, colors.red, colors.black) -- Writes to all windows of the same type
  687. function windowWriteF(param_window, param_text, param_x, param_y, param_textColor, param_backColor)
  688.     local result, functionName = {false, nil}, "windowWriteF"
  689.     Debug("secondary", "debug: "..functionName)
  690.     if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_window, param_text})[2], variableCheck(functionName, {"number"}, {param_x, param_y})[2])[2] then
  691.         result[1] = true
  692.         for a,b in pairs(varList["stdWindows"][param_window]) do result[1] = quickChoice(screenWrite(param_window, a, param_text, param_x, param_y, param_textColor, param_backColor)[1], result[1], false)[2] end
  693.     end
  694.     if not result[1] then console(stringCombine(true, "error: failed windowWrite():", param_window, param_text)[2], 2) end
  695.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  696.     return result
  697. end
  698.  
  699. function backgroundColorF(param_window, param_x, param_y, param_length, param_height, param_backColor)
  700.     local result, functionName, text, y = {false, nil}, "backgroundColorF", nil, param_y
  701.     Debug("secondary", "debug: "..functionName)
  702.     if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_window})[2], variableCheck(functionName, {"number"}, {param_x, param_y, param_length, param_height})[2])[2] then
  703.         for num=1,param_length do text = quickChoice(booleanCheck(text)[1], text.." ", " ")[2] end
  704.         for num=1,param_height do windowWrite(param_window, text, param_x, y, colors.white, param_backColor) y = y + 1 end
  705.     end
  706.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  707.     return result
  708. end
  709.  
  710. console("marker - text functions setup complete")
  711.  
  712. -----------------------------------------------------------------------------------------------------------
  713. -- BUTTON FUNCTIONS -- EMBEDED --
  714. -----------------------------------------------------------------------------------------------------------
  715.  
  716. varList["buttons"], varList["buttonTimer"], varList["redstoneTimer"] = {}, {}, {}
  717.  
  718. function generateButtonF(param_button, param_window)
  719.     local result, functionName = {false, nil}, "generateButtonF"
  720.     Debug("secondary", "debug: "..functionName)
  721.     if variableCheck(functionName, {"string"}, {param_button, param_window})[2] then
  722.         local tempTable, window = varList["buttons"][param_window], param_window
  723.         tempTable = quickChoice(booleanCheck(tempTable[param_button])[1], booleanCheck(tempTable[param_button])[2], false)[2]
  724.         if type(tempTable) == "table" then
  725.             console(stringCombine(true, "command - generateButton():", param_button, param_window)[2])
  726.             if window == "topBar" then tempTable["active"] = quickChoice(multiOrCompare(param_button, varList["currentWindow"]["term"], varList["currentWindow"]["monitor"])[2], true, false)[2] end
  727.             local backColor = quickChoice(tempTable["active"], colors.green, colors.red)[2]
  728.             result[1] = windowWrite(window, tempTable["displayName"]:upper(), tempTable["loc"]["x"], tempTable["loc"]["y"], colors.white, backColor)[1]
  729.         end
  730.     end
  731.     if not result[1] then console(stringCombine(true, "error: failed generateButton():", param_button, param_window)[2], 2) end
  732.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  733.     return result
  734. end
  735.  
  736. function stdPulseF(param_name, param_window)
  737.     local name, window, result, functionName = booleanCheck(param_name)[2], booleanCheck(param_window)[2], {false, nil}, "stdPulseF"
  738.     Debug("secondary", "debug: "..functionName)
  739.     if variableCheck(functionName, {"string"}, {name, window})[2] then
  740.         local tempTable = varList["buttons"][window][name]
  741.         if not tempTable["active"] then
  742.             varList["buttonTimer"][os.startTimer(tempTable["timer"])], result[1] = {["name"] = name, ["window"] = window}, true
  743.         end
  744.         varList["buttons"][window][name]["active"] = not tempTable["active"]
  745.         os.queueEvent("buttonRedraw", name, window)
  746.     end
  747.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  748.     return result
  749. end
  750.  
  751. function stdToggleF(param_name, param_window)
  752.     local result, name, window, functionName = {false, nil}, booleanCheck(param_name)[2], booleanCheck(param_window)[2], "stdToggleF"
  753.     Debug("secondary", "debug: "..functionName)
  754.     if variableCheck(functionName, {"string"}, {name, window})[2] then
  755.         local tempTable = varList["buttons"][window][name]
  756.         if booleanCheck(varList["settings"][tostring(tempTable["act"]["args"])])[1] then varList["settings"][tempTable["act"]["args"]] = quickChoice(varList["settings"][tempTable["act"]["args"]], false, true)[2] end
  757.         varList["buttons"][window][name]["active"] = not tempTable["active"]
  758.         os.queueEvent("buttonRedraw", name, window)
  759.         result[1] = true
  760.     end
  761.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  762.     return result
  763. end
  764.  
  765. function monitorToggleF(param_name, param_window)
  766.     local result, functionName = {false, nil}, "monitorToggleF"
  767.     Debug("secondary", "debug: "..functionName)
  768.     if variableCheck(functionName, {"string"}, {param_name, param_window})[2] then
  769.         varList["monitorList"][param_name]["active"] = quickChoice(varList["monitorList"][param_name]["active"], false, true)[2]
  770.         varList["buttons"]["monitorList"][param_name]["active"] = varList["monitorList"][param_name]["active"]
  771.         os.queueEvent("buttonRedraw", param_name, param_window)
  772.         result[1] = true
  773.     end
  774.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  775.     return result
  776. end
  777.  
  778. function dataChangeF(param_name, param_window)
  779.     local result, name, window, functionName = {false, nil}, booleanCheck(param_name)[2], booleanCheck(param_window)[2], "dataChangeF"
  780.     Debug("secondary", "debug: "..functionName)
  781.     if variableCheck(functionName, {"string"}, {name, window})[2] then
  782.         local tempTable = varList["buttons"][window][name]
  783.         local tempVar = quickChoice(booleanCheck(varList["settings"][tempTable["originalName"]])[1], varList["settings"][tempTable["originalName"]], false)[2]
  784.         if massAndBooleanCheck((tempTable["args"] == "insert"), (type(varList["settings"]["originalName"]) == "string"))[2] then
  785.             os.queueEvent("insertWindow", param_name, param_window)
  786.             result[1] = true
  787.         elseif tempTable["args"] == "<" then
  788.             result[1], varList["settings"][tempTable["originalName"]] = true, quickChoice((type(tempVar) == "boolean"), not tempVar, tempVar)[2]
  789.             result[1], varList["settings"][tempTable["originalName"]] = true, quickChoice((type(tempVar) == "number"), tempVar - 1, tempVar)[2]
  790.         elseif tempTable["args"] == ">" then
  791.             result[1], varList["settings"][tempTable["originalName"]] = true, quickChoice((type(tempVar) == "boolean"), not tempVar, tempVar)[2]
  792.             result[1], varList["settings"][tempTable["originalName"]] = true, quickChoice((type(tempVar) == "number"), tempVar + 1, tempVar)[2]
  793.         end
  794.     end
  795.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  796.     return result
  797. end
  798.  
  799. --addButtonF(param_name, param_window, param_buttonType, param_active, {param_x, param_y}, {param_action, param_args}, param_time, {param_redstone, param_dir, param_invert}, param_displayname)
  800. function addButtonF(param_name, param_window, param_buttonType, param_active, param_location, param_action, param_time, param_redstone, param_displayname)
  801.     local result, active, functionName, display = {false, nil}, booleanCheck(param_active)[2], "addButtonF", quickChoice((tostring(param_displayName) ~= "nil"), param_displayName, param_name)[2]
  802.     Debug("secondary", "debug: "..functionName)
  803.     if massAndBooleanCheck(
  804.     variableCheck(functionName, {"string"}, {param_window, param_name, param_buttonType})[2],
  805.     variableCheck(functionName, {"number"}, param_location)[2]
  806. --  variableCheck(functionName, {"boolean"}, {param_redstone[1], param_redstone[3]})[2],
  807. --  multiOrCompare(param_redstone[2], "left", "right", "top", "bottom", "front", "back", "up", "down")[2]
  808.     )[2] then
  809.  
  810.         local length, param_x, param_y = string.len(" "..param_name.." "), param_location[1], param_location[2]
  811.         if not booleanCheck(varList["buttons"][param_window])[1] then varList["buttons"][param_window] = {} end
  812.        
  813.         if param_buttonType == "toggle" then
  814.             local action, args, Time = quickChoice(booleanCheck(param_action[1])[1], param_action[1], stdToggle)[2], booleanCheck(param_action[2])[2], quickChoice(variableCheck(functionName, {"number"}, {booleanCheck(param_time)[2]})[2], booleanCheck(param_time)[2], 0.1)[2]
  815.             varList["buttons"][param_window][param_name] = {
  816.                 ["displayName"] = " "..display.." ",
  817.                 ["buttonType"] = "toggle",
  818.                 ["act"] = {["act"] = action, ["args"] = args, ["togAct"] = action, ["togArgs"] = args},
  819.                 ["active"] = active,
  820.                 ["orig_active"] = active,
  821.                 ["loc"] = {["x"] = param_x, ["origX"] = param_x, ["y"] = param_y, ["length"] = length},
  822.                 ["originalName"] = param_name,
  823.                 ["timer"] = Time,
  824.                 ["redstone"] = {["redstone"] = param_redstone[1] or false, ["dir"] = booleanCheck(param_redstone[2])[2], ["invert"] = param_redstone[3] or false}
  825.             }
  826.             result[1] = true
  827.  
  828.         elseif param_buttonType == "increment" then
  829.             varList["buttons"][param_window][param_name.."_decrease"] = {
  830.                 ["displayName"] = "< ",
  831.                 ["buttonType"] = "increment",
  832.                 ["act"] = {["act"] = dataChange, ["args"] = "<", ["togAct"] = dataChange, ["togArgs"] = "<"},
  833.                 ["active"] = active,
  834.                 ["orig_active"] = active,
  835.                 ["loc"] = {["x"] = param_x, ["origX"] = param_x, ["y"] = param_y, ["length"] = 2},
  836.                 ["originalName"] = param_name,
  837.                 ["timer"] = Time,
  838.                 ["redstone"] = {["redstone"] = param_redstone[1] or false, ["dir"] = booleanCheck(param_redstone[2])[2], ["invert"] = param_redstone[3] or false}
  839.             }  
  840.             varList["buttons"][param_window][param_name.."_insert"] = {
  841.                 ["displayName"] = " "..display.." ",
  842.                 ["buttonType"] = "increment",
  843.                 ["act"] = {["act"] = dataChange, ["args"] = "insert", ["togAct"] = dataChange, ["togArgs"] = "insert"},
  844.                 ["active"] = active,
  845.                 ["orig_active"] = active,
  846.                 ["loc"] = {["x"] = param_x + 2, ["origX"] = param_x + 2, ["y"] = param_y, ["length"] = length},
  847.                 ["originalName"] = param_name,
  848.                 ["timer"] = Time,
  849.                 ["redstone"] = {["redstone"] = param_redstone[1] or false, ["dir"] = booleanCheck(param_redstone[2])[2], ["invert"] = param_redstone[3] or false}
  850.             }
  851.             varList["buttons"][param_window][param_name.."_increase"] = {
  852.                 ["displayName"] = " >",
  853.                 ["buttonType"] = "increment",
  854.                 ["act"] = {["act"] = dataChange, ["args"] = ">", ["togAct"] = dataChange, ["togArgs"] = ">"},
  855.                 ["active"] = active,
  856.                 ["orig_active"] = active,
  857.                 ["loc"] = {["x"] = param_x + 2 + length, ["origX"] = param_x + 2 + length, ["y"] = param_y, ["length"] = 2},
  858.                 ["originalName"] = param_name,
  859.                 ["timer"] = Time,
  860.                 ["redstone"] = {["redstone"] = param_redstone[1] or false, ["dir"] = booleanCheck(param_redstone[2])[2], ["invert"] = param_redstone[3] or false}
  861.             }
  862.             result[1] = true
  863.  
  864.         elseif param_buttonType == "insert" then
  865.             varList["buttons"][param_window][param_name] = {
  866.                 ["displayName"] = " "..display.." ",
  867.                 ["buttonType"] = "insert",
  868.                 ["act"] = {["act"] = dataChange, ["args"] = "insert", ["togAct"] = dataChange, ["togArgs"] = "insert"},
  869.                 ["active"] = active,
  870.                 ["orig_active"] = active,
  871.                 ["loc"] = {["x"] = param_x, ["origX"] = param_x, ["y"] = param_y, ["length"] = length},
  872.                 ["originalName"] = param_name,
  873.                 ["timer"] = Time,
  874.                 ["redstone"] = {["redstone"] = param_redstone[1] or false, ["dir"] = booleanCheck(param_redstone[2])[2], ["invert"] = param_redstone[3] or false}
  875.             }
  876.             result[1] = true
  877.  
  878.         elseif param_buttonType == "pulse" then
  879.             local action, args, Time = quickChoice(booleanCheck(param_action)[1], booleanCheck(param_action)[2], stdPulse)[2], booleanCheck(param_args)[2], quickChoice(variableCheck(functionName, {"number"}, {booleanCheck(param_time)[2]})[2], booleanCheck(param_time)[2], 0.1)[2]
  880.             varList["buttons"][param_window][param_name] = {
  881.                 ["displayName"] = " "..display.." ",
  882.                 ["buttonType"] = "pulse",
  883.                 ["act"] = {["act"] = action, ["args"] = args, ["togAct"] = action, ["togArgs"] = args},
  884.                 ["active"] = active,
  885.                 ["orig_active"] = active,
  886.                 ["loc"] = {["x"] = param_x, ["origX"] = param_x, ["y"] = param_y, ["length"] = length},
  887.                 ["originalName"] = param_name,
  888.                 ["timer"] = Time,
  889.                 ["redstone"] = {["redstone"] = param_redstone[1] or false, ["dir"] = booleanCheck(param_redstone[2])[2], ["invert"] = param_redstone[3] or false}
  890.             }
  891.             result[1] = true
  892.         end
  893.     end
  894.     if not result[1] then console(stringCombine(true, "error: failed to add button:", param_name, param_window, param_buttonType, param_x, param_y, param_action, param_args, param_actionTog, param_argTog)[2]) end
  895.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  896.     return result
  897. end
  898.  
  899. function monitorListApplyF(param_name, param_window)
  900.     local result, functionName = {false, nil}, "monitorListApplyF"
  901.     Debug("secondary", "debug: "..functionName)
  902.     if variableCheck(functionName, {"string"}, {param_name, param_window}) then
  903.         monitorSetScale()
  904.         stdWindowsCreate()
  905.         generateAllButtons()
  906.         switchWindow("term", "control")
  907.         result[1] = true
  908.     end
  909.     if not result[1] then console(stringCombine(true, "error: failed to generate window:", window)[2], 2) end
  910.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  911.     return result
  912. end
  913.  
  914. function addMonitorListButtonsF()
  915.     varList["buttons"]["monitorList"] = {}
  916.     local result, loc_x, loc_y, functionName = {false, nil}, 2, 2, "addMonitorListButtonsF"
  917.     Debug("secondary", "debug: "..functionName)
  918.     result[1] = addButton("apply", "monitorList", "pulse", false, {loc_x, loc_y}, {monitorListApply, "apply"}, "nil", {nil, nil, nil}, "apply")[1]
  919.     for a,b in pairs(varList["monitorList"]) do
  920.         if a ~= "terminal" then
  921.             loc_y = loc_y + 2
  922.             result[1] = quickChoice(addButton(varList["monitorList"][a]["name"], "monitorList", "toggle", varList["monitorList"][a]["active"], {loc_x, loc_y}, {monitorToggle, varList["monitorList"][a]["name"]}, nil, {nil, nil, nil}, varList["monitorList"][a]["name"])[1], result[1], false)[2]
  923.     end end
  924.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  925.     return result
  926. end
  927.  
  928. function generateWindowButtonsF(param_window)
  929.     local result, window, functionName = {true, nil}, nil, "generateWindowButtonsF"
  930.     if variableCheck(functionName, {"string"}, {param_window})[2] then
  931.         window = quickChoice(booleanCheck(varList["buttons"][param_window])[1], param_window, "update")[2]
  932.     else
  933.         window = "update"
  934.     end
  935.     console(stringCombine(true, "command - start generateWindowButtons():", param_window)[2])
  936.     if window ~= "update" then
  937.         for a,b in pairs(varList["buttons"][window]) do result[1] = quickChoice(generateButton(a, window)[1], result[1], false)[2] end
  938.     else
  939.         for a,b in pairs(varList["buttons"][varList["currentWindow"]["term"]]) do result[1] = quickChoice(generateButton(a, varList["currentWindow"]["term"])[1], result[1], false)[2] end
  940.         for a,b in pairs(varList["buttons"][varList["currentWindow"]["monitor"]]) do result[1] = quickChoice(generateButton(a, varList["currentWindow"]["monitor"])[1], result[1], false)[2] end
  941.     end
  942.     if not result[1] then console(stringCombine(true, "error: failed to generate window:", window)[2], 2) end
  943.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  944.     return result
  945. end
  946.  
  947. function generateAllButtonsF()
  948.     local result, functionName = {true, nil}, "generateAllButtonsF"
  949.     console("command - start generateAllButtons()")
  950.     for a,b in pairs(varList["buttons"]) do result[1] = quickChoice(generateWindowButtons(a)[1], result[1], false)[2] end
  951.     if not result[1] then console("error: failed @ generateAllButtonsF", 2) end
  952.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  953.     return result
  954. end
  955.  
  956. function updateButtonF(...)
  957.     local result, functionName = {false, false}, "updateButtonF"
  958.     os.queueEvent("update")
  959.     stdPulse(...)
  960.     result = {true, true}
  961.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  962.     return result
  963. end
  964.  
  965. function startupScriptF(param_name, param_window)
  966.     local functionName, result, outputFile = "startupScriptF", {false, false}, io.open("startup", "w")
  967.     local startupWrite = {
  968.         "if fs.exists(\"startupTrue\") then\n",
  969.         "    sleep(0.5)\n",
  970.         "    shell.run(\"",
  971.         shell.getRunningProgram(),
  972.         "\")\n",
  973.         "end"
  974.     }
  975.     stdToggle(param_name, param_window)
  976.     if varList["buttons"][param_window][param_name]["active"] then
  977.         local outputFile = io.open("startup", "w")
  978.         result[2] = true
  979.         for a,b in pairs(startupWrite) do result[2] = quickChoice(outputFile:write(b), result[2], false)[2] end
  980.         outputFile:close()
  981.         fs.makeDir("startupTrue")
  982.         if tonumber(os.version()) >= 1.78 then settings.set("shell.allow_startup", true) end
  983.     else
  984.         result[2] = true
  985.         result[2] = quickChoice(fs.delete("startup"), result[2], false)[2]
  986.         result[2] = quickChoice(fs.delete("startupTrue"), result[2], false)[2]
  987.     end
  988.     if result[2] then result[1] = true end
  989.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  990.     return result
  991. end
  992.  
  993. function monitorListWindowF(param_name, param_window)
  994.     local functionName, result = "monitorListWindowF", {false, false}
  995.     stdPulse(param_name, param_window)
  996.     switchWindow("term", "monitorList")
  997.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  998.     return result
  999. end
  1000.  
  1001. function restartF(param_name, param_window)
  1002.     local functionName, result = "restartF", {false, false}
  1003.     stdPulse(param_name, param_window)
  1004.     os.queueEvent("restart")
  1005.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  1006.     return result
  1007. end
  1008.  
  1009. function terminateF(param_name, param_window)
  1010.     local functionName, result = "terminateF", {false, false}
  1011.     stdPulse(param_name, param_window)
  1012.     os.queueEvent("terminate")
  1013.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  1014.     return result
  1015. end
  1016.  
  1017. --addButtonF(param_name, param_window, param_buttonType, param_active, {param_x, param_y}, {param_action, param_args}, param_time, {param_redstone, param_dir, param_invert}, param_displayname)
  1018.  
  1019. function stdButtonsF()
  1020.     local result, functionName = {false, false}, "stdButtonsF"
  1021.     addMonitorListButtons()
  1022.     result[2] = quickChoice(addButton("update", "control", "pulse", false, {2, 3}, {updateButton, "nil"}, 5, {nil, nil, nil}, "update")[2], true, false)[2]
  1023.     result[2] = quickChoice(addButton("startup", "control", "toggle", fs.exists("startup"), {2, 5}, {startupScript, "nil"}, 5, {nil, nil, nil}, "update")[2], result[2], false)[2]
  1024.     result[2] = quickChoice(addButton("monitor list", "control", "pulse", false, {2, 7}, {monitorListWindowF, "nil"}, 5, {nil, nil, nil}, "monitor list")[2], result[2], false)[2]
  1025.     result[2] = quickChoice(addButton("restart", "control", "pulse", false, {2, 9}, {restart, "nil"}, 5, {nil, nil, nil}, "restart")[2], result[2], false)[2]
  1026.     result[2] = quickChoice(addButton("terminate", "control", "pulse", false, {2, 11}, {terminate, "nil"}, 5, {nil, nil, nil}, "terminate")[2], result[2], false)[2]
  1027.     result[1] = quickChoice(result[2], true, false)[2]
  1028.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  1029.     return result
  1030. end
  1031.  
  1032. stdButtons()
  1033. console("marker - button functions setup complete")
  1034.  
  1035. -----------------------------------------------------------------------------------------------------------
  1036. -- TOPBAR SETUP -- EMBEDED --
  1037. -----------------------------------------------------------------------------------------------------------
  1038.  
  1039. --local scroll, topBarLength = 0, 0
  1040. varList["scroll"], varList["topBarLength"] = 1, 0
  1041.  
  1042. function topBarScrollF(param_arg)
  1043.     local arg, result, functionName = booleanCheck(param_arg)[2], {false, nil}, "topBarScrollF"
  1044.     if variableCheck(functionName, {"string"}, {arg})[2] then
  1045.         if massAndBooleanCheck((arg == ">"), (varList["topBarLength"] > ((-1 * varList["scroll"]) + termX - 6)))[2] then
  1046.             varList["scroll"] = varList["scroll"] - 10
  1047.         elseif massAndBooleanCheck((arg == "<"), (varList["scroll"] ~= 1))[2] then
  1048.             varList["scroll"] = varList["scroll"] + 10
  1049.         end
  1050.         local tempList = varList["buttons"]["topBar"]
  1051.         for a,b in pairs(varList["buttons"]["topBar"]) do varList["buttons"]["topBar"][a]["loc"]["x"] = quickChoice((varList["scroll"] < -5), (tempList[a]["loc"]["origX"] - varList["scroll"]), tempList[a]["loc"]["origX"])[2] end
  1052.         result[1] = true
  1053.     end
  1054.     clearWindow("topBar")
  1055.     generateWindowButtons("topBar")
  1056.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  1057.     return result
  1058. end
  1059.  
  1060. function topBarChangeF(param_screen, param_window)
  1061.     local screen, result, functionName = quickChoice((param_screen == "monitor_touch"), "monitor", "term")[2], {false, nil}, "topBarChangeF"
  1062.     if variableCheck(functionName, {"string"}, {param_screen, param_window})[2] then
  1063.         result = switchWindow(param_screen, param_window)
  1064.         generateWindowButtons("topBar")
  1065.     end
  1066.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  1067.     return result
  1068. end
  1069.  
  1070. function topBarButtonsF()
  1071.     local result, functionName, x, offset = {false, false}, "topBarButtonsF", 1, string.len(" < ")
  1072.     result[2] = quickChoice(addButton("<", "scroll<", "pulse", false, {1, 1}, {topBarScroll, "<"}, 5, {nil, nil, nil}, "scroll<"), true, false)[2]
  1073.     result[2] = quickChoice(addButton(">", "scroll>", "pulse", false, {termX - 3, 1}, {topBarScroll, ">"}, 5, {nil, nil, nil}, "scroll>"), result[2], false)[2]
  1074.     for a,b in pairs(varList["stdWindowsData"]) do
  1075.         if varList["stdWindowsData"][a]["topBar"] then
  1076.             result[2] = quickChoice(addButton(a, "topBar", "toggle", false, {offset, 1}, {topBarChange, a}, 5, {nil, nil, nil}, a), result[2], false)[2]
  1077.             offset = offset + string.len(" "..a.." ")
  1078.         end
  1079.     end
  1080.     result[1] = result[2]
  1081.     varList["topBarLength"] = offset
  1082.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  1083.     return result
  1084. end
  1085.  
  1086. function buttonScanF(param_screen, param_X, param_Y)
  1087.     local result, screen, functionName, tempTable = {false, false}, param_screen, "buttonScanF", {}
  1088.     if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_screen})[2], variableCheck(functionName, {"number"}, {param_X, param_Y})[2])[2] then
  1089.         if param_Y == 1 then
  1090.        
  1091.             if tolerance(varList["buttons"]["scroll>"][">"]["loc"]["x"], param_X, varList["buttons"]["scroll>"][">"]["loc"]["length"], 0)[2] or tolerance(varList["buttons"]["scroll<"]["<"]["loc"]["x"], param_X, varList["buttons"]["scroll<"]["<"]["loc"]["length"], 0)[2] then
  1092.                 console("scrolls selected")
  1093.                 if tolerance(varList["buttons"]["scroll<"]["<"]["loc"]["x"], param_X, varList["buttons"]["scroll<"]["<"]["loc"]["length"], 0)[2] then
  1094.                     result[2] = topBarScroll("<")[1]
  1095.                 elseif tolerance(varList["buttons"]["scroll>"][">"]["loc"]["x"], param_X, varList["buttons"]["scroll>"][">"]["loc"]["length"], 0)[2] then
  1096.                     result[2] = topBarScroll(">")[1]
  1097.                 end
  1098.             else
  1099.                 console("switch windows selected")
  1100.                 for a,b in pairs(varList["buttons"]["topBar"]) do
  1101.                     tempTable = varList["buttons"]["topBar"][a]
  1102.                     result[2] = quickChoice(massAndBooleanCheck((tempTable["loc"]["y"] == param_Y), tolerance(tempTable["loc"]["x"], param_X, tempTable["loc"]["length"], 0)[2])[2], a, result[2])[2]
  1103.                 end
  1104.                 if result[2] ~= false then varList["buttons"]["topBar"][result[2]]["act"]["act"](screen, result[2]) console(stringCombine(false, "-", result[2], "-")[2]) end
  1105.             end
  1106.            
  1107.         else
  1108.             console("buttons selected")
  1109.             screen = quickChoice(multiOrCompare(param_screen, "monitor", "monitor_touch")[2], "monitor", screen)[2]
  1110.             screen = quickChoice(multiOrCompare(param_screen, "term", "mouse_click")[2], "term", screen)[2]
  1111.             console(screen)
  1112.             if booleanCheck(varList["buttons"][varList["currentWindow"][screen]])[1] then
  1113.                 for a,b in pairs(varList["buttons"][varList["currentWindow"][screen]]) do
  1114.                     tempTable = varList["buttons"][varList["currentWindow"][screen]][a]
  1115.                     result[2] = quickChoice(massAndBooleanCheck((tempTable["loc"]["y"] == param_Y), tolerance(tempTable["loc"]["x"], param_X, tempTable["loc"]["length"], 0)[2])[2], a, result[2])[2]
  1116.                 end
  1117.             end
  1118.             if result[2] ~= false then console(stringCombine(true, "Button found:", result[2], screen)[2]) varList["buttons"][varList["currentWindow"][screen]][result[2]]["act"]["act"](result[2], varList["currentWindow"][screen]) end
  1119.         end
  1120.     end
  1121.     if result[2] ~= false then result[1] = true end
  1122.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  1123.     return result
  1124. end
  1125.  
  1126. topBarButtons()
  1127. generateAllButtons()
  1128. console("Marker - topBar functions setup complete")
  1129.  
  1130. -----------------------------------------------------------------------------------------------------------
  1131. -- SECONDARY FUNCTIONS -- EMBEDED --
  1132. -----------------------------------------------------------------------------------------------------------
  1133.  
  1134. --  event = eventFilter("timer", "monitor_touch", "mouse_click", "key", "etc") .. returns a table only when the event matches the arg --
  1135. function eventFilterF(...)
  1136.     local tempList, whitelist, result, text, functionName, blacklisted = {...}, {}, {false, false}, "eventFilter:", "eventFilterF", {"eventFilter Blacklisted:"}
  1137.     for a,b in pairs(tempList) do whitelist[b] = true end
  1138.     while not result[1] do
  1139.         result[2] = {os.pullEvent()}
  1140.         if booleanCheck(whitelist[result[2][1]])[2] == false then
  1141.             table.insert(blacklisted, result[2][1])
  1142.             Debug(stringCombine(true, "debug", functionName, "blacklist:", result[2])[2])
  1143.         else
  1144.             result[1] = true
  1145.         end
  1146.     end
  1147.     console(stringCombine(true, text, result[2])[2])
  1148.     console(stringCombine(true, blacklisted)[2])
  1149.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  1150.     return result
  1151. end
  1152.  
  1153. function insertWindowF(param_name, param_window)
  1154.     local result, functionName, active, event, text, writing, upperCase, shiftKey, capsLock, currWindow = {false, false}, "insertWindowF", true, nil, {}, false, false, false, false, varlist["currentWindow"]["term"]
  1155.     if variableCheck(functionName, {"string"}, {param_name, param_window})[2] then
  1156.         clearWindow("message")
  1157.         backgroundColor("message", 1, 1, termX, termY, colors.blue)
  1158.         switchWindow("term", "message")
  1159.        
  1160.         local tempTable = varList["buttons"][param_window][param_name]
  1161.         local tempVar = quickChoice(booleanCheck(varList["settings"][tempTable["originalName"]])[1], varList["settings"][tempTable["originalName"]], false)[2]
  1162.         resultType = type(tempVar) == "boolean"
  1163.        
  1164.         windowWrite("message", "ENTER VARIABLE:", (termX / 2) - 9, (termY / 2) - 1, colors.white, colors.blue)
  1165.         writing = true
  1166.         while writing do
  1167.             event = eventFilter("char", "key")[2]
  1168.             if event[1] == "char" then
  1169.                 table.insert(text, event[2])
  1170.             elseif keys.getName(event[2]) == "enter" then
  1171.                 writing = false
  1172.             elseif keys.getName(event[2]) == "backspace" then
  1173.                 if booleanCheck(text[1])[1] then text[table.maxn(text)] = nil end
  1174.             end
  1175.             backgroundColor("message", 1, (termX / 2) + 1, termX, 1, colors.blue)
  1176.             windowWrite("message", stringCombine(false, text)[2], (termX / 2) - 9, (termY / 2) + 1, colors.white, colors.blue)
  1177.         end
  1178.        
  1179.         text = quickChoice(booleanCheck(text[1])[1], stringCombine(false, text)[2], nil)[2]
  1180.         if massAndBooleanCheck(resultType == "boolean", multiAndCompare(tostring(text):lower(), "true", "false", "t", "f", "1", "0", "+", "-")[2])[2] then
  1181.             result = {true, quickChoice(multiAndCompare(text:lower(), "true", "t", "1", "+")[2], true, false)[2]}
  1182.         elseif massAndBooleanCheck(resultType == "number", booleanCheck(tonumber(text))[1])[2] then
  1183.             result = {true, tonumber(text)}
  1184.         elseif resultType == "string" and booleanCheck(text)[1] then
  1185.             result = {true, text}
  1186.         end
  1187.        
  1188.         if result[1] then
  1189.             varList["settings"][tempTable["originalName"]] = result[2]
  1190.         else
  1191.             os.queueEvent("messageWindow", stringCombine(true, "Error:", resultType, "expected")[2], 2)
  1192.         end
  1193.        
  1194.         switchWindow("term", currWindow)
  1195.         clearWindow("message")
  1196.         backgroundColor("message", 1, 1, termX, termY, colors.blue)
  1197.     end
  1198.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  1199.     return result
  1200. end
  1201.  
  1202. function messageWindowF(param_event, param_text, param_currWindowTerm, param_currWindowMon)
  1203.     local result, functionName = {false, false}, "messageWindowF"
  1204.     if variableCheck(functionName, {"string"}, {param_event, param_text})[2] then
  1205.         if param_event == "messageWindow" then
  1206.             clearWindow("message") backgroundColor("message", 1, 1, termX, termY, colors.blue)
  1207.             windowWrite("message", param_text, ((termX / 2) - (string.len(param_text) / 2)), (termY / 2), colors.white, colors.blue)
  1208.             switchWindow("both", "message")
  1209.         elseif param_event == "timer" then
  1210.             switchWindow("term", param_currWindowTerm) switchWindow("monitor", param_currWindowMon)
  1211.             clearWindow("message") backgroundColor("message", 1, 1, termX, termY, colors.blue)
  1212.         end
  1213.     end
  1214.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  1215.     return result
  1216. end
  1217.  
  1218. function peripheralListRegisterSingleF(param_listName)
  1219.     local result, functionName, tempList = {false, false}, "peripheralListRegisterSingleF", false
  1220.     if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_listName})[2], booleanCheck(varList["peripheralList"][param_listName])[1])[2] then
  1221.         varList["peripheralList"][param_listName]["peripherals"] = {}
  1222.         for a,b in pairs(varList["peripheralList"][param_listName]["mode"]) do
  1223.             tempList = peripheralFind(b, varList["peripheralList"][param_listName]["variables"][a])[2]
  1224.             if booleanCheck(tempList)[2] ~= false then
  1225.                 for c,d in pairs(tempList) do
  1226.                     local duplicate = false
  1227.                     for e,f in pairs(varList["peripheralList"][param_listName]["peripherals"]) do duplicate = quickChoice(d == f, true, duplicate)[2] end
  1228.                     if not duplicate then table.insert(varList["peripheralList"][param_listName]["peripherals"], d) result[1] = true end
  1229.                 end
  1230.         end end
  1231.     end
  1232.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  1233.     return result
  1234. end
  1235.  
  1236. function peripheralListRegisterMultiF()
  1237.     local result, functionName = {false, false}, "peripheralListRegisterMultiF"
  1238.     for a,b in pairs(varList["peripheralList"]) do
  1239.         peripheralListRegisterSingle(a) result[1] = true
  1240.     end
  1241.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  1242.     return result
  1243. end
  1244.  
  1245. function peripheralListAddF(param_tableName, param_mode, param_variable)
  1246.     local result, functionName = {false, false}, "peripheralListAddF"
  1247.     if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_tableName, param_mode})[2], variableCheck(functionName, {"table"}, {param_variable})[2], multiOrCompare(param_mode, "type", "method")[2])[2] then
  1248.         varList["peripheralList"] = quickChoice(booleanCheck(varList["peripheralList"])[1], varList["peripheralList"], {})[2]
  1249.         varList["peripheralList"][param_tableName] = quickChoice(booleanCheck(varList["peripheralList"][param_tableName])[1], varList["peripheralList"][param_tableName], {["peripherals"] = {}, ["mode"] = {}, ["variables"] = {}})[2]
  1250.         table.insert(varList["peripheralList"][param_tableName]["mode"], param_mode)
  1251.         table.insert(varList["peripheralList"][param_tableName]["variables"], param_variable)
  1252.         peripheralListRegisterSingle(param_tableName)
  1253.     end
  1254.     Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
  1255.     return result
  1256. end
  1257.  
  1258. console("Marker - SECONDARY FUNCTIONS functions setup complete")
  1259.  
  1260. -----------------------------------------------------------------------------------------------------------
  1261. -- COROUTINE FUNCTIONS -- EMBEDED --
  1262. -----------------------------------------------------------------------------------------------------------
  1263.  
  1264. coroutineControl = {["function"] = {}, ["driver"] = {}, ["coroutine"] = {}}
  1265.  
  1266. do
  1267.     coroutineControl["function"]["yielder"] = function()
  1268.         sleep(0.5)
  1269.         os.queueEvent("start")
  1270.         return
  1271.     end
  1272.    
  1273.     coroutineControl["function"]["resize"] = function()
  1274.         local event, x = nil, 0
  1275.         while true do
  1276.             event = eventFilter("monitor_resize")[2]
  1277.             x = x + 1
  1278.             console("clearing resize"..x)
  1279.     end end
  1280.  
  1281.  
  1282.     coroutineControl["function"]["buttonScan"] = function()
  1283.         local event = nil
  1284.         while true do
  1285.             event = eventFilter("monitor_touch", "mouse_click")[2]
  1286.             buttonScan(event[1], event[3], event[4])
  1287.     end end
  1288.  
  1289.     coroutineControl["function"]["buttonRedraw"] = function()
  1290.         local event = nil
  1291.         while true do
  1292.             event = eventFilter("buttonRedraw")[2]
  1293.             generateButton(event[2], event[3])
  1294.     end end
  1295.  
  1296.     coroutineControl["function"]["buttonReset"] = function()
  1297.         local event, tempTable = nil, nil
  1298.         while true do
  1299.             event = eventFilter("timer")[2]
  1300.             tempTable = booleanCheck(varList["buttonTimer"][event[2]])[2]
  1301.             if tempTable ~= false then
  1302.                 varList["buttons"][tempTable["window"]][tempTable["name"]]["act"]["act"](tempTable["name"], tempTable["window"])
  1303.                 varList["buttonTimer"][event[2]] = nil
  1304.     end end end
  1305.  
  1306.     coroutineControl["function"]["redstoneControl"] = function()
  1307.         local event = nil
  1308.         while true do
  1309.             event = eventFilter("timer", "redstone", "monitor_touch", "mouse_click")[2]
  1310.             if booleanCheck(varList["redstoneTimer"][event[2]])[2] ~= false then
  1311.                 generateButton(varList["redstoneTimer"][event[2]]["name"], varList["redstoneTimer"][event[2]]["window"])
  1312.                 varList["redstoneTimer"][event[2]] = false
  1313.     end end end
  1314.  
  1315.     coroutineControl["function"]["osControl"] = function()
  1316.         local event = nil
  1317.         while true do
  1318.             event = eventFilter("update", "restart", "terminate")[2]
  1319.             if event[1] == "update" then
  1320.                 update(shell.getRunningProgram(), pastebinCode)
  1321.             elseif event[1] == "restart" then
  1322.                 os.reboot()
  1323.             elseif event[1] == "terminate" then
  1324.                 fs.delete("startupTrue")
  1325.                 os.reboot()
  1326.             end
  1327.     end end
  1328.  
  1329.     coroutineControl["function"]["peripherialControl"] = function()
  1330.         local event = nil
  1331.         while true do
  1332.             event = eventFilter("peripheral", "peripheral_detach")[2]
  1333.             peripheralListRegisterMultiF()
  1334.     end end
  1335.  
  1336.     coroutineControl["function"]["insertWindow"] = function()
  1337.         local event = nil
  1338.         while true do
  1339.             event = eventFilter("insertWindow")[2]
  1340.             insertWindow(event[2], event[3])
  1341.     end end
  1342.  
  1343.     coroutineControl["function"]["messageWindow"] = function()
  1344.         local event, timer, currWindowTerm, currWindowMon = nil, nil, nil, nil
  1345.         while true do
  1346.             event = eventFilter("messageWindow", "timer")[2]
  1347.             currWindowTerm = quickChoice(varList["currentWindow"]["term"] ~= "message", varList["currentWindow"]["term"], currWindowTerm)[2]
  1348.             currWindowMon = quickChoice(varList["currentWindow"]["monitor"] ~= "message", varList["currentWindow"]["monitor"], currWindowMon)[2]
  1349.             timer = quickChoice(event[1] == "message", os.startTimer(event[3]), timer)[2]
  1350.             if massAndBooleanCheck(event[1] == "timer", timer == event[2])[2] or event[1] == "message" then messageWindow(event[1], event[2], currWindowTerm, currWindowMon) end
  1351.     end end
  1352.  
  1353.     coroutineControl["function"]["save"] = function()
  1354.         local event = nil
  1355.         while true do
  1356.             event = os.pullEvent()
  1357.             tempTable = booleanCheck(varList["buttonTimer"][event[2]])[2]
  1358.             if tempTable ~= false then
  1359.                 varList["buttons"][tempTable["window"]][tempTable["name"]]["act"]["act"](tempTable["name"], tempTable["window"])
  1360.                 varList["buttonTimer"][event[2]] = nil
  1361.     end end end
  1362. end
  1363.  
  1364. -----------------------------------------------------------------------------------------------------------
  1365. -- COROUTINE COROUTINES -- EMBEDED --
  1366. -----------------------------------------------------------------------------------------------------------
  1367.  
  1368. for a,b in pairs(coroutineControl["function"]) do coroutineControl["coroutine"][a] = coroutine.create(b) end
  1369.  
  1370. -----------------------------------------------------------------------------------------------------------
  1371. -- COROUTINE DRIVERS -- EMBEDED --
  1372. -----------------------------------------------------------------------------------------------------------
  1373.  
  1374. for a,b in pairs(coroutineControl["coroutine"]) do
  1375.     coroutineControl["driver"][a] = function() -- coroutine driver in parallel
  1376.         local r, tFilter, eventData = b, nil, {}
  1377.         while true do
  1378.             if r then
  1379.                 if tFilter == nil or tFilter == eventData[1] or eventData[1] == "terminate" then
  1380.                     local ok, param = coroutine.resume( r, unpack(eventData) )
  1381.                     if not ok then error( param ) else tFilter = param end
  1382.                     if coroutine.status( r ) == "dead" or eventData[1] == "terminate" then
  1383.                         r, event = nil, "terminate"
  1384.                         return
  1385.             end end end
  1386.             eventData = { os.pullEventRaw() }
  1387.     end end
  1388. end  
  1389.  
  1390. -----------------------------------------------------------------------------------------------------------
  1391. -- MAIN PROGRAM -- PROGRAM -- INSERT CUSTOM PROGRAM HERE --
  1392. -----------------------------------------------------------------------------------------------------------
  1393.  
  1394. -----------------------------------------------------------------------------------------------------------
  1395. -- COROUTINE -- PROGRAM --
  1396. -----------------------------------------------------------------------------------------------------------
  1397.  
  1398. -----------------------------------------------------------------------------------------------------------
  1399. -- COROUTINE DRIVERS -- EMBEDED --
  1400. -----------------------------------------------------------------------------------------------------------
  1401.  
  1402.  
  1403.  
  1404. -----------------------------------------------------------------------------------------------------------
  1405. -- END -- EMBEDED --
  1406. -----------------------------------------------------------------------------------------------------------
  1407.  
  1408. parallel.waitForAll(coroutineControl["driver"]["yielder"],
  1409.                     coroutineControl["driver"]["resize"],
  1410.                     coroutineControl["driver"]["buttonScan"],
  1411.                     coroutineControl["driver"]["buttonRedraw"],
  1412.                     coroutineControl["driver"]["buttonReset"],
  1413.                     coroutineControl["driver"]["redstoneControl"],
  1414.                     coroutineControl["driver"]["osControl"],
  1415.                     coroutineControl["driver"]["peripherialControl"],
  1416.                     coroutineControl["driver"]["insertWindow"],
  1417. --                  coroutineControl["driver"]["messageWindow"],
  1418.                     coroutineControl["driver"]["save"]
  1419. )
Advertisement
Add Comment
Please, Sign In to add comment