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

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

Started by theplonkerking, 17 December 2012 - 11:42 AM
theplonkerking #1
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
theoriginalbit #2
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?
theplonkerking #3
Posted 17 December 2012 - 12:57 PM
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
remiX #4
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
warfar #5
Posted 17 December 2012 - 01:03 PM
you need rednet.open("side") on recieving computer
theplonkerking #6
Posted 17 December 2012 - 01:09 PM
you need rednet.open("side") on recieving computer

you are a genius! I knew I was missing something dead simple!
remiX #7
Posted 17 December 2012 - 01:14 PM
you need rednet.open("side") on recieving computer

Always miss the most obvious ><
theoriginalbit #8
Posted 17 December 2012 - 01:15 PM
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/>
theplonkerking #9
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])
theoriginalbit #10
Posted 17 December 2012 - 02:08 PM
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!
theplonkerking #11
Posted 17 December 2012 - 02:43 PM
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 :(/>
theoriginalbit #12
Posted 17 December 2012 - 03:01 PM
after confirming here http://computercraft.info/wiki/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