This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Andrew2060's profile picture

[ICBM] [help please]

Started by Andrew2060, 26 July 2015 - 02:35 PM
Andrew2060 #1
Posted 26 July 2015 - 04:35 PM

Hey guys,


I have a ModPack and was testing out icbms with computers, installed all the latest stuff for CC, peripherals, sensors etc.

I am trying to launch a missile wirelessly, by inputting coordinates into a pc from the control room of my submarine, and expecting them to be configured into the missile through another computer attached to the ICBM launch control panel.


Launch Computer:

so i enter the amount of missile waves i want to launch (1-infinity)

Then i enter the x, y and z coordinates for the destination.

It sleeps, then reloads the program.


Silo Computer:

Says an error occurred on line 9.




Can someone help me fix this please or tell me what i did wrong??


LaunchPC:

http://pastebin.com/fYytQpPt


SiloPC:

http://pastebin.com/avNGSq5w


thanks
Andrew2060 #2
Posted 26 July 2015 - 04:51 PM
it sends the information, just doesnt use it for some reason and errors in the silo computer.
flaghacker #3
Posted 26 July 2015 - 05:48 PM
What is the exact/full error message? Did it really say "An error occured on line 9"?

A couple of comments on your code in advance:

*Lauch code, line 50

local launchCoords = textutils.unserialize('{["x"]='..x..',["y"]='..y..',["z"]='..z..'}')
You can create a table like this instead:

local launchCoords = {x=x, y=y, z=z}
No more weird hacks needed ;)/>/>

*Silo code, line 9:

icbm.setTarget(launchCoords["x"],launchCoords["y"],launchCoords["z"])
Tables can be accessed a bit easier using the dot syntax:

icbm.setTarget(lauchCoords.x, lauchCoords.y, lauchCoords.z)

*Silo code, line 15-21 can be simplified using the id filter build in to rednet, you pass it as a parameter:

id, msg = rednet.receive(masterID)
if msg == "CheckIn" then
  rednet.send(masterID, os.getComputerID())
  print("Sent ready message")
else
  dowork(msg)
end

I also removed the useless elseif and I used some more descriptive variable names.
Edited on 26 July 2015 - 04:02 PM
Andrew2060 #4
Posted 26 July 2015 - 06:23 PM
Thank's so much :)/>

Owe ya one.
flaghacker #5
Posted 26 July 2015 - 06:40 PM
Thank's so much :)/>/>/>

Owe ya one.

Glad I could help. What was the problem exactly? :D/>/>
Edited on 26 July 2015 - 04:40 PM
Andrew2060 #6
Posted 26 July 2015 - 06:50 PM
The problem was writing code on a server, where nukes fly everywhere
No spot is safe, its my server and being the co owner im at the highest risk so, have to write code while being submerged.

if you wanna check out my modpack http://www.technicpack.net/modpack/nuclear-revolution.689897/discuss
flaghacker #7
Posted 26 July 2015 - 06:54 PM
The problem was writing code on a server, where nukes fly everywhere
No spot is safe, its my server and being the co owner im at the highest risk so, have to write code while being submerged.

if you wanna check out my modpack http://www.technicpack.net/modpack/nuclear-revolution.689897/discuss

No, I mean, is your error fixed? Because none of what I said should fix any errors. That's why I asked
What is the exact/full error message? Did it really say "An error occured on line 9"?

But if your problem is gone, that's good too.
Andrew2060 #8
Posted 26 July 2015 - 06:58 PM
Wait hold on, slightly confused if i use the code you provided would it work?

Not being the guy who wants others to do his own work, just trying to shield my submarine faster.
Ive been working on this ModPack for ages and has been driving me nuts to get the server/client working properly.

Brain is not working, if you could be slightly specific on where i should tweak it?.

I have an idea of what to do with the tables, and to serialize them but not particularly a fan of tables or rednet.

How would i do something like, it asks you to enter x, y, z and then fills those values into the table, serializes them and sends them to the SiloPc which would then use the received message to input coordinates into the launchpad and fire the missile.
flaghacker #9
Posted 26 July 2015 - 07:03 PM
No, the things I said are improvement tips, they don't change anything about the code but the readability. I can't help you without the exact error message the computer printed. Could you post it? "An error on line 9" is a bit vague, what video?

What version of computercraft are you using? If it's a recentish version, you can send tables via rednet without serialization.
Andrew2060 #10
Posted 26 July 2015 - 07:08 PM
yeah sure.

im not sure, its an old version though.
I cant use the latest version with OpenCCsensors
Andrew2060 #11
Posted 26 July 2015 - 07:17 PM
http://imgur.com/a/2cLKX
flaghacker #12
Posted 26 July 2015 - 07:31 PM
Try do do all changes I previously suggested, it will generally improve the code. These additional things will actually solve your problem :)/>

You misspelled launchCoords on line 7 in the silo program. Additionally, change line 8 to

launchCoords = textutils.unserialize(launchCoords)
to unserialize the rednet message.

Finally, change line 50 in the launch program to

local lauchCoords = textutils.serialize({x=x, y=y, z=z})
because you haver to send a serialized table.

Serializing is converting a table to a string, unserializing is converting it back. You kinda got the wrong way around in this code.
Edited on 26 July 2015 - 05:35 PM
Andrew2060 #13
Posted 27 July 2015 - 08:54 AM
need more help please XD
flaghacker #14
Posted 27 July 2015 - 09:24 AM
need more help please XD

I literally said "change line … to …, line … to … and line … to …".

Does it still not work? Or is there something you don't understand?
Andrew2060 #15
Posted 27 July 2015 - 09:31 AM
Still does not work lol

gets this error, textutils:117 error cantonating string and
nil

take a look:


SpoilerLaunchPC



term.clear()
term.setCursorPos(1,1)
print("==========================================")
print("		   Skynet Defense Systems		 ")
print("==========================================")
rednet.open("back")
-----------------------------SiloFunction----------------------------
allSilos = {}

function getSilos()
		allSilos = {}
		rednet.broadcast("CheckIn")
		checking = true
		while checking do
				x = nil
				y = nil
				x,y = rednet.receive(2)
				if x ~= nil and y ~= nil then
						table.insert(allSilos, y)
				else
						checking = false
				end
		end
end
---------------------To get the active silos ID's---------------------
while true do
		print("==========================================")
		print("			Launch Interface			  ")
		print("==========================================")
		print("[1] ListSilos")
		print("[2] Launch")
		input = read()
		if input == "1" then
				getSilos()
				term.setCursorPos(1,20)
				print("List of available silos:")
				for _,ID in pairs(allSilos) do
						print("Silo #"..ID.." ready for launch.")
				end
---------------------------Launch Control-----------------------------
				elseif input == "2" then
				print("Enter # of launches.")
				local launches = read()
				print("Location Tracking...")
				print("X:")
				tonumber(read())
				print("Y:")
				tonumber(read())
				print("Z:")
				tonumber(read())

				local lauchCoords = textutils.serialize({"x"== x, "y"== y, "z"== z})
				for i=1,tonumber(launches) do
						for _,silo in pairs(allSilos) do
								rednet.send(tonumber(silo),launchCoords)
								sleep(4)
						end
				end
		end
end

SiloPC


lSide = "back"
masterID = 80
rednet.open("top")

icbm = peripheral.wrap(lSide)

function dowork(launchCoords)
		launchCoords = textutils.unserialize(launchCoords)
		icbm.setTarget(launchCoords["x"],launchCoords["y"],launchCoords["z"])
		icbm.launch()
		sleep(1.5)
end

while true do
		x,y = rednet.receive ()
		if y == "CheckIn" and x == masterID then
				rednet.send(masterID, os.getComputerID())
				print("Sent ready message")
		elseif x == masterID and y ~= "CheckIn" then
				dowork(y)
		end
end
Edited on 27 July 2015 - 07:33 AM
Andrew2060 #16
Posted 27 July 2015 - 09:39 AM
Sorry i mean

Textutils:177 attempt to concatenate string and
nil
Edited on 27 July 2015 - 07:47 AM
flaghacker #17
Posted 27 July 2015 - 09:48 AM
Change the part where you ask the target coordinates to this:

print("X:")
x = tonumber(read())
print("Y:")
y = tonumber(read())
print("Z:")
z = tonumber(read())
You forgot to capture the rusult of tonumber

This line is still wrong, that should be a single '=' and the quotes are unnesseccary.

local lauchCoords = textutils.serialize({"x"== x, "y"== y, "z"== z})
corrected code:

local lauchCoords = textutils.serialize({x=x, y=y, z=z})

Does that fix the error? And, actually, what computer gives that error?

Could you also type

edit rom/apis/textutils
and navidage to line 117 and take a screenshot?
Edited on 27 July 2015 - 07:51 AM
Andrew2060 #18
Posted 27 July 2015 - 09:51 AM
nope,

is it possible you can come online or if you have a skype we can talk there easily?

Skype = Burnin.Aura
Modpack = PostBlast
Platform = Technic 4.0
IP= Inside modpack when downloaded.
flaghacker #19
Posted 27 July 2015 - 09:53 AM
Ah no sorry, I'm at my grandparent's house with a really bad internet connection and I'm on my phone :(/>. Maybe tonight when I get home… I edited my provious post, could you try that as well?
Andrew2060 #20
Posted 27 July 2015 - 12:22 PM
brings a list of all the functions i can use with the api.
flaghacker #21
Posted 27 July 2015 - 12:57 PM
brings a list of all the functions i can use with the api.

I think you forgot the 'edit' part…
Andrew2060 #22
Posted 27 July 2015 - 01:52 PM
yeah sure
http://imgur.com/a/T3cmz
Lyqyd #23
Posted 27 July 2015 - 07:41 PM
You say you've made changes to your code, but you haven't posted the most recent version of the code.