Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Important: Computer must be next to a stargate computercraft interact block AND have a wireless modem on the back.
- -- Current status: Handles the initial dial and sends query through. Still need to code far side listener and reply.
- -- Algorithm:
- -- Listen for incoming modem message to send query.
- -- Send query through gate via sgSendMessage.
- -- Get reply via same method.
- -- Send reply out via wireless.
- shell.run("clear")
- -- Wrap peripherals
- wifi = peripheral.wrap("back")
- sg = peripheral.wrap("left")
- -- Define variables
- queryType = "fuel" -- Will eventually be set via remote connection over the modem.
- sgState, chevrons = sg.stargateState() -- So we know whether we need to dial or not.
- reactorGate = true -- So we know if we need to clean up the gate afterward or not.
- reactorAddress = "3DIGTJU78" -- The address of the gate the reactor is at.
- -- First, check to see if the gate is open. If it is, we don't need to dial. If it's not, we need a connection.
- -- Check the gate to see if it's idle, remote,
- function gateCheck()
- -- May need to shuffle logic around a bit.
- sgState = sg.stargateState()
- if sgState == "Connected" and sg.remoteAddress() == reactorAddress then
- reactorGate = false
- print("Gate is active and connected to correct address.")
- elseif (sgState == "Connected" and sg.remoteAddress() ~= reactorAddress) or sgState ~= "Idle" then
- reactorGate = true
- print("Gate is active and connected to different address. Will dial upon disconnect.")
- while true do
- sgState = sg.stargateState()
- if sgState == "Connected" and sg.remoteAddress() == reactorAddress then
- print("Connected to correct address.")
- reactorGate = true
- break
- elseif sgState == "Idle" then
- print("Gate has gone idle. Dialling.")
- stargateDial()
- break
- end
- os.sleep(2)
- end
- else
- reactorGate = true
- print("Gate is inactive. Dialling.")
- stargateDial()
- end
- print("Pretend the query ran here.")
- end
- -- Custom dialler for this program
- function stargateDial()
- -- Need to dial the gate and wait for it to be open before doing any sort of further work.
- sg.dial(reactorAddress)
- event, source, gateStatus, oldStatus = os.pullEvent("sgStargateStateChange")
- while gateStatus ~= "Connected" do
- event, source, gateStatus, oldStatus = os.pullEvent("sgStargateStateChange")
- end
- print("Gate open. Beginning query.")
- end
- function gateQuery()
- print("Sending query: ", queryType)
- sg.sendMessage(queryType)
- -- Receive reply
- --event, where, value = os.pullEvent("sgMessageReceived")
- end
- function gateCleanup(reactorGate)
- if reactorGate then
- print("Closing gate.")
- sg.disconnect()
- end
- end
- gateCheck()
- gateQuery()
- gateCleanup(reactorGate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement