Jump to content




Sending Info From a table to another Computer


  • You cannot reply to this topic
6 replies to this topic

#1 computercraftrules89

  • Members
  • 28 posts

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)))

#2 bjornir90

  • Members
  • 378 posts
  • LocationFrance

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 ^_^/>

#3 computercraftrules89

  • Members
  • 28 posts

Posted 11 November 2012 - 01:20 AM

If i Run gettarget with that added code i get.

gettarget:8: attempt to call table

#4 Jasonfran

  • Members
  • 148 posts
  • LocationEngland

Posted 11 November 2012 - 01:36 AM

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

To

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


#5 bjornir90

  • Members
  • 378 posts
  • LocationFrance

Posted 11 November 2012 - 01:47 AM

View PostJasonfran, on 11 November 2012 - 01:36 AM, said:

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

#6 computercraftrules89

  • Members
  • 28 posts

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.

#7 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

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