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

Sending Info From a table to another Computer

Started by computercraftrules89, 10 November 2012 - 11:45 PM
computercraftrules89 #1
Posted 11 November 2012 - 12:45 AM
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)))
bjornir90 #2
Posted 11 November 2012 - 01:13 AM
I thinl you can use serialize to send only one message :unsure:/>/> 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 ^_^/>/>
computercraftrules89 #3
Posted 11 November 2012 - 01:20 AM
If i Run gettarget with that added code i get.

gettarget:8: attempt to call table
Jasonfran #4
Posted 11 November 2012 - 01:36 AM
Change

coordTarg { tostring(targetX), tostring(targetY), tostring(targetZ) }

To


coordTarg = { tostring(targetX), tostring(targetY), tostring(targetZ) }
bjornir90 #5
Posted 11 November 2012 - 01:47 AM
Change

coordTarg { tostring(targetX), tostring(targetY), tostring(targetZ) }

To


coordTarg = { tostring(targetX), tostring(targetY), tostring(targetZ) }
Sorry I forgot the "=" :/ I cant test it but it should work
computercraftrules89 #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.
Orwell #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] )