Posted 02 December 2015 - 05:47 PM
Hey,
Overview:
I generally design defense programs for whomever that requires it, like myself.
Currently i am working on perfecting a program that utilizes information from a radar to act on.
The program has one purpose and one purpose only, to shoot down incoming missiles.
Functionality:
-1. Server program utilizes radar data.
-2. Incoming target coordinates are serialized and sent to silo's.
-3. The server will continue sending the latest coordinates of target(s) to silos.
-4. Once the target breaches a failsafe, the radar will output a redstone signal.
-5. The redstone signal goes into the left of the PC, triggering firing action.
-6. The server tells the silos to fire at the missile's last sent coordinates.
-7. each silo should have a delay so that they do not fire at the same time.
What i am having an issue with in this program:
(The host is this program im working on)
(The Host controls a network of slave PC's)
Would be appreciated if someone can instruct me as to where my error lies.
As well as propose the way it could be fixed or re rewritten.
Pastebin links:
Master = http://pastebin.com/vK6jGNge
Slave = http://pastebin.com/exm7HRhr
The problem lies somewhere in obtaining/generating values for the ""Msg"" to silos.
The program works fine until it detects a missile, then it tells me there is something wrong on the line i serialize it on.
{I screwed up the BB code some how in that post, so it wont show the line numbers and what not.}
The error is the maptxt = textutils.serialize(maptab)
Thanks in advance!
Overview:
I generally design defense programs for whomever that requires it, like myself.
Currently i am working on perfecting a program that utilizes information from a radar to act on.
The program has one purpose and one purpose only, to shoot down incoming missiles.
Functionality:
-1. Server program utilizes radar data.
-2. Incoming target coordinates are serialized and sent to silo's.
-3. The server will continue sending the latest coordinates of target(s) to silos.
-4. Once the target breaches a failsafe, the radar will output a redstone signal.
-5. The redstone signal goes into the left of the PC, triggering firing action.
-6. The server tells the silos to fire at the missile's last sent coordinates.
-7. each silo should have a delay so that they do not fire at the same time.
What i am having an issue with in this program:
(The host is this program im working on)
(The Host controls a network of slave PC's)
- Not sure if it is serializing the coordinates gained by the radar "x, y, z"
- Not sure if it is communicating to the other slave silo computers.
- Have no idea why it seems to error when it detects a missile.
Spoiler
- –[[Anti-Ballistic Missile Server by Andrew2060]]–
–[[Settings]]–
local modemSide = "top"
local waitDelay = 2
allDat = 0
–[[Init]]–
rednet.open(modemSide)
local silos = {}
–[[Functions]]–
local function clear()
term.clear()
term.setCursorPos(1, 1)
end
term.setBackgroundColor(colors.blue)
clear()
local function findSilos()
rednet.broadcast("ping silo")
local timerID = os.startTimer(waitDelay)
while true do
event, id, msg, distance = os.pullEvent()
if event == "rednet_message" and msg == "pong" then
table.insert(silos, id)
timerID = os.startTimer(waitDelay)
elseif event == "timer" and id == timerID then
return
end
end
end
local function printSilos()
clear()
print("===============================")
print(" [Detected silos] ")
for k, v in ipairs(silos) do
print(" silo #" .. k .. " id = "..v)
end
print("===============================")
term.setBackgroundColor(colors.red)
print(" ")
print(" ")
term.setBackgroundColor(colors.blue)
end
–[[Main program]]–
findSilos()
while true do
printSilos()
if redstone.getInput("left") then
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.red)
print("Incomming targets:")
term.setTextColor(colors.white)
maptab = peripheral.call("back","getEntities")
maptxt = textutils.serialize(maptab)
if maptxt ~= "{}" then
allDat = 0
for num in pairs(maptab) do
allDat = allDat+1
end
targets = allDat/3
for i=0,targets-1 do
local x = math.floor(tonumber(maptab["x_"..i])/1)
local y = math.floor(tonumber(maptab["y_"..i])/1)
local z = math.floor(tonumber(maptab["z_"..i])/1)
local msg = {x,y,z}
rednet.send(silos[i], msg)
end
print("Target #"..i.." at X:"..x.." Y:"..y.." Z:"..z.")
end
end
sleep(.0001)
end
Would be appreciated if someone can instruct me as to where my error lies.
As well as propose the way it could be fixed or re rewritten.
Pastebin links:
Master = http://pastebin.com/vK6jGNge
Slave = http://pastebin.com/exm7HRhr
The problem lies somewhere in obtaining/generating values for the ""Msg"" to silos.
The program works fine until it detects a missile, then it tells me there is something wrong on the line i serialize it on.
{I screwed up the BB code some how in that post, so it wont show the line numbers and what not.}
The error is the maptxt = textutils.serialize(maptab)
Thanks in advance!
Edited on 02 December 2015 - 04:49 PM