Jump to content




Trying to send a table but the receiving computer doesn't display anything


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

#1 theplonkerking

  • New Members
  • 5 posts

Posted 17 December 2012 - 12:42 PM

ok I'm not sure what the problem with my code is, it isn't generating any errors but the receiving terminal does not display the information.

this is what the sending computer has:
wood = {12, 12, }
print("what you want?")
local item = read()
print("how many?")
local amount = read()
if item == "wood" then
table.insert (wood, amount)
local msg = textutils.serialize(wood)
rednet.open("right")
rednet.send (2, msg)
end

and this is what the receiving computer has:
local id, msg = rednet.receive()
local wood = textutils.unserialize(msg)
print (wood[1])
print (wood[2])
print (wood[3])

I'm not entirely sure what im doing really all of what I have done so far has been accomplished by looking at the manual or the forums, but as they say the best way to learn is from your mistakes.

thanks plonkerking

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 December 2012 - 12:44 PM

ok this may sound like its a stupid question but it has to be asked. is the receiving computers ID actually 2?

#3 theplonkerking

  • New Members
  • 5 posts

Posted 17 December 2012 - 12:57 PM

View PostTheOriginalBIT, on 17 December 2012 - 12:44 PM, said:

ok this may sound like its a stupid question but it has to be asked. is the receiving computers ID actually 2?

yep the receiving computer is id 2

#4 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 17 December 2012 - 01:02 PM

On the receiving PC change the code to this maybe:

id, msg = rednet.receive()
wood = textutils.unserialize(msg)
print (wood[1])
print (wood[2])
print (wood[3])

Making it local might be the prob

#5 warfar

  • Members
  • 22 posts

Posted 17 December 2012 - 01:03 PM

you need rednet.open("side") on recieving computer

#6 theplonkerking

  • New Members
  • 5 posts

Posted 17 December 2012 - 01:09 PM

View Postwarfar, on 17 December 2012 - 01:03 PM, said:

you need rednet.open("side") on recieving computer

you are a genius! I knew I was missing something dead simple!

#7 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 17 December 2012 - 01:14 PM

View Postwarfar, on 17 December 2012 - 01:03 PM, said:

you need rednet.open("side") on recieving computer

Always miss the most obvious ><

#8 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 December 2012 - 01:15 PM

View Posttheplonkerking, on 17 December 2012 - 01:09 PM, said:

View Postwarfar, on 17 December 2012 - 01:03 PM, said:

you need rednet.open("side") on recieving computer

you are a genius! I knew I was missing something dead simple!

haha its ok, apparently remiX and I did too :P

#9 theplonkerking

  • New Members
  • 5 posts

Posted 17 December 2012 - 01:33 PM

great another problem!
I was trying to make the turtle move based off the variables produced but it didn't work, would you kind people please take a look and help me fix it :)
rednet.open("right")

local id, msg = rednet.receive()

t = textutils.unserialize(msg)


local togo = tonumber(t[1])
local amount = tonumber(t[1])

function tfuel(amount)

if turtle.getFuelLevel() < 5 then

turtle.select(16)

turtle.refuel(amount)

turtle.select(1)

end
end

function turnaround()

turtle.turnRight()

turtle.turnRight()
end


for i = 1, togo do
tfuel(1)
turtle.forward()
end
turnaround()
for r = 1, togo do

tfuel(1)

turtle.forward()
end

Edit: I fixed it on my own was just me being a plonker as my name states :P
apparantley you cant have 2 variables go into another variable
these were wrong:
local togo = tonumber(t[1])
local amount = tonumber(t[1])

#10 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 December 2012 - 02:08 PM

View Posttheplonkerking, on 17 December 2012 - 01:33 PM, said:

apparantley you cant have 2 variables go into another variable
these were wrong:
local togo = tonumber(t[1])
local amount = tonumber(t[1])

what is it saying? because you are able to!

#11 theplonkerking

  • New Members
  • 5 posts

Posted 17 December 2012 - 02:43 PM

View PostTheOriginalBIT, on 17 December 2012 - 02:08 PM, said:

View Posttheplonkerking, on 17 December 2012 - 01:33 PM, said:

apparantley you cant have 2 variables go into another variable
these were wrong:
local togo = tonumber(t[1])
local amount = tonumber(t[1])

what is it saying? because you are able to!

dont know it was just frezzing and not working. Also do you know how to control how many items a turtle will suck from a chest? I've done a couple of searches but everything i tried failed :(

#12 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 December 2012 - 03:01 PM

after confirming here http://computercraft...iki/Turtle_(API)

since suck doesn't seem to have an amount i would say you should do this:
turtle.select(1)
turtle.suck()      -- get an entire stack
amountPulled = turtle.getItemCount()
amountDesired = 8
-- do some checks here to make sure the amount sucked is greater than the amount wanted then do this if there is more
turtle.drop(amountPulled - amountDesired) -- put back how many you dont want






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users