Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Script by Savage_Me55iah of CraftAU.com.au--
- --Other Savage_Me55iah scripts @ http://pastebin.com/u/Savage_Me55iah
- --INSTRUCTIONS ON USE--
- --Instruction video on http://youtube.com/savagemessiah5
- --Contact Savage_Me55iah @ CraftAU.com.au or http://www.computercraft.info/forums2/ with suggestions/fixes/bugs
- local scriptName = "booleanmanip"
- fileDetail = fileDetail or {}
- fileDetail[scriptName] = {["version"] = 0.1, ["pastebin"] = "irkktmgP"}
- local tArgs = {...}
- if tArgs[1] == "update" then
- print("UPDATING") shell.run("pastebin get "..fileDetail[scriptName].pastebin.." "..scriptName.."_update")
- if fs.exists(scriptName.."_update") then fs.remove(shell.getRunningProgram()) fs.copy(scriptName.."_update", shell.getRunningProgram()) fs.remove(scriptName.."_update") print("UPDATE SUCCESS") else print("UPDATE FAILED") end
- end
- -----------------------------------------------------------------------------------------------------------
- -- Variables --
- -----------------------------------------------------------------------------------------------------------
- local errorLoc = "Datastore/Errors/Error"
- -----------------------------------------------------------------------------------------------------------
- -- API Functions --
- -----------------------------------------------------------------------------------------------------------
- -- BACKSLASH WAS MESSING WITH MY SCRIPT EDITOR, I WILL NOT BE JUDGED!
- function BS() local result = "\\" return result end
- -- booleanmanip.check(functionNum, variable) -- [1] returns true if function ran correctly OR if false variable was nil [2] returns variable OR false if nil
- -- used for bypassing nil errors
- function check(param_functionNum, param_value)
- local result, functionNum = {false, nil}, tostring(param_functionNum).."/001"
- if tostring(param_value) ~= "nil" then result = {true, param_value} else result = {false, false} end
- return result
- end
- -- booleanmanip.quickChoice(functionNum, boolean, value, value) -- [1] returns function ran correctly [2] returns result
- -- removes alot of standard "if" blocks
- function quickChoice(param_functionNum, param_boolean, param_true, param_false)
- local result, functionNum, variable = {false, false}, param_functionNum.."/002", check(functionNum, param_boolean)[2]
- if type(variable) == "boolean" then
- if variable == true then result = {true, param_true or true} else result = {true, param_false or false} end
- else
- logger.logger(functionNum, {"Function Error, Expected: booleanmanip.quickChoice(functionNum, boolean, value, value)"}, 2, " ")
- end
- return result
- end
- -- booleanmanip.massCheck(functionNum, "and", {boolean, boolean, etc}) -- [1] returns function ran correctly [2] returns result
- -- removes alot of "and/or"
- function massCheck(param_functionNum, param_function, param_booleans)
- local result, functionNum, variable_function ={false, false}, param_functionNum.."/003", tostring(param_function)
- if variable_function == "and" or variable_function == "or" then
- if type(param_booleans) == "table" then
- if param_function == "and" then
- result = {false, true}
- for a,b in pairs(param_booleans) do result = {true, quickChoice(functionNum, b, result[2], false)[2]} end
- else
- for a,b in pairs(param_booleans) do result = {true, quickChoice(functionNum, b, true, result[2])[2]} end
- end
- else
- logger.logger(functionNum, {"Function Error, Expected: booleanmanip.massCheck(functionNum, (and/or), {boolean, boolean, etc})"}, 2, " ")
- end
- else
- logger.logger(functionNum, {"Function Error, Expected: booleanmanip.massCheck(functionNum, (and/or), {boolean, boolean, etc})"}, 2, " ")
- end
- return result
- end
- -- booleanmanip.multiCompare(functionNum, "and", variable, {variable, variable, etc}) -- [1] returns function ran correctly [2] returns result
- -- compares multiple variables to 1 variable
- function multiCompare(param_functionNum, param_function, param_arg, param_variables)
- local result, functionNum, variable_function = {false, false}, param_functionNum.."/004", tostring(param_function)
- if massCheck(functionNum, "and", {massCheck(functionNum, "or", {(variable_function == "and"), (variable_function == "or")})[2], check(functionNum, param_arg)[1], (type(check(functionNum, param_variables)[2]) == "table")})[2] then
- if param_function == "and" then
- result = {false, true}
- for a,b in pairs(param_variables) do result = {true, quickChoice(functionNum, (param_arg == check(functionNum, b)[2]), result[2], false)[2]} end
- else
- for a,b in pairs(param_variables) do result = {true, quickChoice(functionNum, (param_arg == check(functionNum, b)[2]), true, result[2])[2]} end
- end
- else
- logger.logger(functionNum, {"Function Error, Expected: booleanmanip.multiCompare(functionNum, (and/or), variable, {variable, variable, etc})"}, 2, " ")
- end
- return result
- end
- -- tolerance(param_functionNum, "relative", 10, 5, 6, -1) -- [1] returns function ran correctly [2] returns result
- -- returns boolean if value is within tolerance
- function tolerance(param_functionNum, param_function, param_target, param_value, param_tolerancePositive, param_toleranceNegative)
- local result, functionNum = {false, false}, param_functionNum.."/005"
- local tolerancePositive, toleranceNegative = param_tolerancePositive or 0, param_toleranceNegative or 0
- if multiCompare(functionNum, "and", "number", {type(check(functionNum, param_target)[2]), type(check(functionNum, param_value)[2])})[2] and type(check(functionNum, param_function)[2]) == "string" then
- if param_function == "relative" then
- tolerancePositive, toleranceNegative = param_target + tolerancePositive, param_target + toleranceNegative
- end
- result = {true, quickChoice(functionNum, massCheck(functionNum, "and", {(param_value <= tolerancePositive), (param_value >= toleranceNegative)})[2])[2]}
- else
- logger.logger(functionNum, {"Function Error, Expected: booleanmanip.tolerance(functionNum, relative, number, number, number, number)"}, 2, " ")
- end
- return result
- end
- -- booleanmanip.variableCheck(functionNum, {type, type, etc}, {variable, variable, etc}) -- [1] returns function ran correctly [2] returns result
- -- returns boolean if all of the variables in the 2nd table matches any of the types in the 1st table
- function variableCheck(param_functionNum, param_type, param_variable)
- local result, functionNum = {false, false}, param_functionNum.."/007"
- local tempTable = {}
- if multiCompare(functionNum, "and", "table", {type(param_type), type(param_variable)})[2] then
- for a,b in pairs(param_variable) do
- tempTable[a] = false
- for c,d in pairs(param_type) do
- if massCheck(functionNum, "and", {check(functionNum, b)[1], check(functionNum, d)[1]})[2] then
- tempTable[a] = quickChoice(functionNum, (d == type(b)), true, tempTable[a])[2]
- end end end
- for a,b in pairs(tempTable) do result = {true, quickChoice(functionNum, tempTable[a], tempTable[a], false)[2]} end
- else
- logger.logger(functionNum, {"Function Error, Expected: booleanmanip.variableCheck(functionNum, {type}, {variable, variable, etc})"}, 2, " ")
- end
- return result
- end
- -- booleanmanip.even(functionNum, number) -- [1] returns function ran correctly [2] returns result
- -- returns boolean if value is an even number
- function even(param_functionNum, param_variable)
- local result, functionNum = {false, false}, param_functionNum.."/006"
- if variableCheck(functionNum, {"number"}, {param_variable})[2] then
- result = {true, quickChoice(functionNum, (param_variable % 2 == 0))[2]}
- else
- logger.logger(functionNum, {"Function Error, Expected: booleanmanip.even(functionNum, number)"}, 2, " ")
- end
- return result
- end
- -----------------------------------------------------------------------------------------------------------
- -- Old Functions --
- -----------------------------------------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment