Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Generic API Code
- --Set this at the beginning
- local hostname = "";
- --Basic Setup Code
- local filePath = "basalt.lua" --here you can change the file path that it installs to. default: /basalt.lua
- if not(fs.exists(filePath))then
- shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
- end
- local basalt = require(filePath:gsub(".lua", "")) -- here you can change the variablename in any variablename you want default: basalt
- local modemSide;
- --checks every side to identify which side has the ender modem on.
- if peripheral.getType("top") == "modem" then modemSide = "top";
- elseif peripheral.getType("right") == "modem" then modemSide = "right";
- elseif peripheral.getType("left") == "modem" then modemSide = "left";
- elseif peripheral.getType("front") == "modem" then modemSide = "front";
- elseif peripheral.getType("back") == "modem" then modemSide = "back";
- elseif peripheral.getType("bottom") == "modem" then modemSide = "bottom";
- else
- print("Error: Modem not found. Please add modem onto machine");
- os.exit();
- end
- if hostname == "" then
- print("Hostname not set, please set the host name at the top of the script");
- os.exit();
- end
- local protocol = "API";
- rednet.unhost(protocol, hostname);
- if rednet.lookup(protocol, hostname) ~= nil then
- print("Hostname is already in use. Please pick a different hostname");
- os.exit();
- end
- rednet.host(protocol,hostname);
- print("Set hostname to " .. hostname);
- local apiData = {};
- local systemStatus = "online";
- function api() --Specifically For Communicating Data, Do not have commands in here
- while true do
- local from, message = rednet.receive(protocol);
- if message == "check" then
- rednet.send(from, systemStatus, protocol);
- elseif message == "getData" then
- modem.send(from, "online", protocol);
- end
- end
- end
- function logic()
- end
- parallel.waitForAll(api, logic);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement