Hi all Just figured out how to get the target from my ICBM Launcher (Out of the ICBM Mod).
Now ild like to get the program to send the data it receives from the launcher to another computer
heres the code.
program gettarget
rednet.open("top")
gettarget = peripheral.wrap("right")
local targetX, targetY, targetZ = gettarget.getTarget()
print("X: ", tostring(targetX))
print("Y: ", tostring(targetY))
print("Z: ", tostring(targetZ))
rednet.send(1, write("X: ", string(targetX)))
rednet.send(1, write("X: ", string(targetY)))
rednet.send(1, write("X: ", string(targetZ)))
Sending Info From a table to another Computer
Started by computercraftrules89, Nov 11 2012 12:45 AM
6 replies to this topic
#1
Posted 11 November 2012 - 12:45 AM
#2
Posted 11 November 2012 - 01:13 AM
I thinl you can use serialize to send only one message
/> like so
/>
rednet.open("top")
gettarget = peripheral.wrap("right") -- I think the peripheral is the launcher ?
[color=#282828][font=helvetica, arial, sans-serif]local targetX, targetY, targetZ = gettarget.getTarget()[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]print("X: ", tostring(targetX))[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]print("Y: ", tostring(targetY))[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]print("Z: ", tostring(targetZ))[/font][/color]
coordTarg { tostring(targetX), tostring(targetY), tostring(targetZ) }
coordSerial = textutils.serialize(coordTarg)
rednet.send(1, coordSerial)
-- On the other computer :
id, msgSerial = rednet.receive() -- or anything to retrieve the message
coordTarg = textutils.unserialize(msgSerial)
-- then you have to retrieve the data :
print(coordTarg.1) --for X coord ect ect
hope tht help #3
Posted 11 November 2012 - 01:20 AM
If i Run gettarget with that added code i get.
gettarget:8: attempt to call table
gettarget:8: attempt to call table
#4
Posted 11 November 2012 - 01:36 AM
Change
To
coordTarg { tostring(targetX), tostring(targetY), tostring(targetZ) }
To
coordTarg = { tostring(targetX), tostring(targetY), tostring(targetZ) }
#6
Posted 11 November 2012 - 01:49 AM
Cool the first computer is working and sending to Computer one however running a program to get the target brings forth another error.
bios:338: [string "gettarget"]:5: ')' expected
and the code is
rednet.open("top")
id, msgSerial = rednet.receive()
coordTarg = textutils.unserialize(msgSerial)
print(coordTarg.1)
Fixed
change
print(coordTarg.1)
to
print(msgSerial)
thanks to all who helped out now I can get my missle target from the computer at my base.
and with my other code I can send the launcher a target
and yeah even launch all from the safety of the base.
bios:338: [string "gettarget"]:5: ')' expected
and the code is
rednet.open("top")
id, msgSerial = rednet.receive()
coordTarg = textutils.unserialize(msgSerial)
print(coordTarg.1)
Fixed
change
print(coordTarg.1)
to
print(msgSerial)
thanks to all who helped out now I can get my missle target from the computer at my base.
and with my other code I can send the launcher a target
and yeah even launch all from the safety of the base.
#7
Posted 11 November 2012 - 02:04 AM
It's rather simple, coordTarg.1 only works if the 1 is a string in the table. But it's an integer, so you'd rather do this:
print( coordTarg[1] )
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












