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

REDNET ICBM LAUNCHER NOT FUNCTIONING

Started by Kadecamz, 09 September 2012 - 10:04 PM
Kadecamz #1
Posted 10 September 2012 - 12:04 AM
I'm trying to make a program that will launch missiles using rednet broadcasting, reading of ID and msg and wireless redstone.
It works by (Or atleast what I am trying to do) having you enter the number of which missile silo you want to launch.
Then it broadcasts a custom code depending on the 1-6 number you chose.
Then another computer built on an obsidian tower picks that up and then broadcasts another code
Then two computers hooked up to wireless redstone blocks pick those up, and one of them will give a redstone pulse to the wireless transmitter block that gets sent to the missile silo, launching the missile.
I am 100% SURE this is an error with the code (BTW, no error message or anything)


This code is where the launch person enters the silo number to launch


term.clear()
sleep(0)
term.setCursorPos(1,1)
sleep(0)
rednet.open("top")
print(os.getComputerID())
print(" ")
print("Enter the silo number to launch,")
print(" ")
print("[1]")
print("[2]")
print("[3]")
print("[4]")
print("[5]")
print("[6]")
print("or all")
print(" ")
write("Launch silo number ")
numl = read()
print("Launching silo number "..numl)
rednet.broadcast("launchnumber"..numl)
sleep(3)
shell.run("startup")
if numl == "all" then
rednet.broadcast("launchall")
print("Launching all missiles.")
sleep(3)
shell.run("startup")
end

This is the code on the obsidian tower.


print(os.getComputerID())
print(" ")
print(" ")
while true do
rednet.open("top")
id, msg = rednet.receive()
if id == "1" and msg == "launchnum1" then
rednet.broadcast("launch1")
print("1launch")
elseif id == "1" and msg == "launchnum2" then
rednet.broadcast("launch2")
elseif id == "1" and msg == "launchnum3" then
rednet.broadcast("launch3")
elseif id == "1" and msg == "launchnum4" then
rednet.broadcast("launch4")
elseif id == "1" and msg == "launchnum5" then
rednet.broadcast("launch5")
elseif id == "1" and msg == "launchnum6" then
rednet.broadcast("launch6")
elseif id == "1" and msg == "launchall" then
rednet.broadcast("lanall")
end
end

This is the code for the two receiving computers that emmit a redstone pulse to launch the missiles


rs.setOutput("front",false)
rs.setOutput("right",false)
rs.setOutput("left",false)
print("This sends to 3-6 missiles")
rednet.open("top")
id, msg = rednet.receive()
if id == "2" and msg == "launch4" then
rs.setOutput("front",true)
sleep(1)
shell.run("startup")
elseif id == "2" and msg == "launch5" then
rs.setOutput("left",true)
sleep(1)
shell.run("startup")
elseif id == "2" and msg == "launch6" then
rs.setOUtput("right",true)
sleep(1)
shell.run("startup")
end

and


rs.setOutput("front",false)
rs.setOutput("left",false)
rs.setOutput("right",false)
print("This sends to 1-3 missiles")
rednet.open("top")
id, msg = rednet.receive()
if id == "2" and msg == "launch1" then
rs.setOutput("front",true)
sleep(1)
shell.run("startup")
if id == "2" and msg == "launch2" then
rs.setOutput("left",true)
sleep(1)
shell.run("startup")
if id == "2" and msg == "launch3" then
rs.setOutput("right",true)
sleep(1)
shell.run("startup")
end
end
end

Hope you guys can help
Please don't put it all into one computer, i like it using four computers.
Kadecamz #2
Posted 10 September 2012 - 12:38 AM
Please help. D:
Lyqyd #3
Posted 10 September 2012 - 01:25 AM
So what's the problem? You say it doesn't work, but what doesn't work? What debugging have you done?
NIN3 #4
Posted 10 September 2012 - 01:51 AM
Hmm, im not sure. are they close enough togeather to recevive? (how far apart are they?)
Kadecamz #5
Posted 10 September 2012 - 03:56 AM
lyqd, the problem is that it just doesn't do what its suppost to do.
no error or anything.

I think its a problem with the obsidian tower code.

And i have the rednet range set to 9999999999999999999999999999999
Sammich Lord #6
Posted 10 September 2012 - 04:12 AM
The is problems on all of it.
I was re-writing the program for you then I good bored so I'll just tell you the obvious errors.
First off you did not use elseif you just used if's which is bad.
You also don't need two computer to launch 6 missals.
If I get bored again I'll write it for you.
Kadecamz #7
Posted 10 September 2012 - 12:35 PM
I did use elseifs.
If you rewrite it for me, please do not put it all into one computer.
I want it to be using four computers, like how it is.
Kadecamz #8
Posted 10 September 2012 - 12:36 PM
BTW. I did use elseif.
Kadecamz #9
Posted 10 September 2012 - 07:45 PM
The point of this is to use four computers to do one thing.
Kadecamz #10
Posted 10 September 2012 - 10:44 PM
Bump.
Lyqyd #11
Posted 11 September 2012 - 12:58 AM
Don't quadruple post, please. Have you done any debugging on this yourself?
NIN3 #12
Posted 11 September 2012 - 01:08 AM
Can you make the programs run on each computer? Do they have motums? We need more info, and we need more error codes.
Kadecamz #13
Posted 11 September 2012 - 01:57 AM
@Lygyd
Yes, I know that for some reason the tower won't broadcast when i broadcast the message that makes the tower broadcast.

@NIN3
Yes, they're all running, they all have modems and they're all open
And I told you.
The program isn't doing what its suppost to do, there isn't any error code.
NIN3 #14
Posted 11 September 2012 - 02:01 AM
So can you break it down any? can you make the towner save an out put (like, output redstone should it get the message)
and see if that makes it work?
Kadecamz #15
Posted 11 September 2012 - 02:56 AM
NIN, I tried that with print. nothing.
NIN3 #16
Posted 11 September 2012 - 03:24 AM
So I ask, how far from the sending computer, to the obsidian tower? If you move closer does it work?
Kadecamz #17
Posted 11 September 2012 - 04:02 AM
I set my rednet range to 999999999999999999999999999999999.
And either way, they're pretty close together.
evilguard #18
Posted 11 September 2012 - 04:32 AM
I dont know if that can help but your code kinda look like one i have made. its a REALLY simple one that just toggle a piston on rednet. But for some weird reason it never work at first. I alway have to write the password a second time to make it work.

so its ask for password, i put it, nothing happen. it reboot, ask again for password, i enter the password again and it work. since your code look like mine i would suggest you to send the order twice and see what happen.

Good luck :D/>/>
Lyqyd #19
Posted 11 September 2012 - 05:04 AM
You didn't read through your code very well. The one sends this:


rednet.broadcast("launchnumber"..numl)

And the second one is waiting for:


if id == "1" and msg == "launchnum1" then

See the problem?
Kadecamz #20
Posted 11 September 2012 - 05:05 AM
If you mean type the same number into the main computer twice, then yes.
I have done that.
Kadecamz #21
Posted 11 September 2012 - 05:07 AM
@Lyqyd
I saw that, i thought it would work how I did it.
Time to add a bunch of else and elseifs. :D/>/>

EDIT: BTW! You got 499 posts!
Lyqyd #22
Posted 11 September 2012 - 05:07 AM
No, read it carefully. You're sending "launchnumber1" and the other is waiting for "launchnum1".

Edit: Wait, you thought it would work to send a completely different string than the other computer was waiting for and that it would just magically know what you meant… by magic?

Also, you can edit posts. Please do so instead of posting multiple times in a row without anyone posting between.
Edited on 11 September 2012 - 03:10 AM
Kadecamz #23
Posted 11 September 2012 - 05:11 AM
oh wow…i'm retarded.

EDIT: STILL not working. I modded the console program to use elseifs.


term.clear()
sleep(0)
term.setCursorPos(1,1)
sleep(0)
rednet.open("top")
print(os.getComputerID())
print(" ")
print("Enter the silo number to launch,")
print(" ")
print("[1]")
print("[2]")
print("[3]")
print("[4]")
print("[5]")
print("[6]")
print("or all")
print(" ")
write("Launch silo number ")
numl = read()
if numl == "1" then
rednet.broadcast("launchnumber1")
print("Launching silo "..numl)
elseif numl == "2" then
rednet.broadcast("launchnumber2")
print("Launching silo "..numl)
redo()
elseif numl == "3" then
rednet.broadcast("launchnumber3")
print("Launching silo "..numl)
redo()
elseif numl == "4" then
rednet.broadcast("launchnumber4")
print("Launching silo "..numl)
redo()
elseif numl == "5" then
rednet.broadcast("launchnumber5")
print("Launching silo "..numl)
redo()
elseif numl == "6" then
rednet.broadcast("launchnumber6")
print("Launching solo "..numl)
redo()
function redo() --For redoing to quickly launch more missiles.
sleep(3)
shell.run("startup")
end
elseif numl == "all" then
rednet.broadcast("launchall")
print("Launching all missiles.")
sleep(3)
shell.run("startup")
end
Zoinky #24
Posted 11 September 2012 - 05:39 AM
You can't have the function on the bottom. The interpreter reads from top to bottom, Like us. Move it to the top :S
Kadecamz #25
Posted 11 September 2012 - 05:49 AM
Fixed the function, but the tower still is not working.
Luanub #26
Posted 11 September 2012 - 06:15 AM
Did you update the towers code as well?

Like change

if id == "1" and msg == "launchnum1" then

to

if id == "1" and msg == "launchnumber1" then
Zoinky #27
Posted 11 September 2012 - 06:53 AM
Did you update the towers code as well?

Like change

if id == "1" and msg == "launchnum1" then

to

if id == "1" and msg == "launchnumber1" then

It's a string… It shouldn't matter?
Luanub #28
Posted 11 September 2012 - 11:21 AM
It definitely matters. That's like saying that the number's 1 and 2 are the same because they are numbers, and that it doesnt matter if you do if id == "1" or if id == "2"(which is also wrong, the id's are number not strings see below on how to compare a number.)

If the var msg is the string "launchnumber1" then it ~= the string "launchnum1" since they are not the same, and the conditions for the if statement will not be met.

The if statement should look something like.

if id == 1 and msg == "launchnumber1" then -- no " around numbers, just strings


EDIT: A little debugging hint. You can use the type() function to check and see what the var is to ensure you are checking it correctly.

Here's an example using rednet.receive()

local id, msg, distance = rednet.receive()
local idType = type(id)
local msgType = type(msg)
local distanceType = type(distance)
print(idType)
print(msgType)
print(distanceType)
Edited on 11 September 2012 - 09:27 AM
Kadecamz #29
Posted 12 September 2012 - 07:56 PM
@Luan!
That was the problem! :)/>/>
It was the "" around the numbers!!!
TY so much!


waaaaitttt. now the things that recieve a message from the tower won't work. >:/
Lyqyd #30
Posted 13 September 2012 - 01:08 AM
Do they have the same problem?
Kadecamz #31
Posted 13 September 2012 - 01:19 AM
I fixed their ID "es.
didnt fix it.
eh either way I froze that whole section of the world with an enderthermic missile.
ETHANATOR360 #32
Posted 13 September 2012 - 02:41 AM
the problem is your not using rednet.open
Kadecamz #33
Posted 13 September 2012 - 04:03 AM
You didn't even bother to read my code, wow.
Luanub #34
Posted 13 September 2012 - 08:07 AM
Can you update the OP with your current updated code?
Zoinky #35
Posted 13 September 2012 - 08:17 AM
the problem is your not using rednet.open

5th line.