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

Got a rednet problem.

Started by IndustrialLemon, 24 April 2015 - 02:07 AM
IndustrialLemon #1
Posted 24 April 2015 - 04:07 AM
Here's the problem. I'm getting the error "test:20: attempt to concentrate string and nil" when the computer recieves the rednet message.

Heres the code
tx = 0
ty = 0
tz = 0
px = 0
py = 0
pz = 0
pid = 0
rednet.open("right")
tx, ty, tz = gps.locate()
print(tx.." "..ty.." "..tz)
--while true do
pid, px, py, pz = rednet.receive()
print(px.." "..py.." "..pz)
HPWebcamAble #2
Posted 24 April 2015 - 04:28 AM
That code is 13 lines, but the error says line 20

Are you sure thats the full code?
Bomb Bloke #3
Posted 24 April 2015 - 04:30 AM
Not that this script consists of 20 lines, but that last line you've got there would trigger that error. rednet.receive() returns three values, and you're assigning the to four variables - so the fourth, pz, is going to be nil. Heck, unless you specified a protocol when sending, the third'll be nil, too.

Did you mean…?:

pid, pmsg = rednet.receive()
print(pmsg)
KRHN #4
Posted 24 April 2015 - 01:02 PM

pid, px, py, pz = rednet.receive()

rednet.receive() aren't returns location, just returns id, message, distance.
Edited on 24 April 2015 - 11:03 AM
Cing #5
Posted 24 April 2015 - 01:10 PM
I think you mean gps.locate() not rednet.receive() but you have then still three variables.
Edited on 24 April 2015 - 11:11 AM
Anavrins #6
Posted 24 April 2015 - 02:02 PM
You're trying to concatenate " " (a string) with pz, which in this case is nil because rednet.receive doesn't return 4 values, it return the sender's id, the actual message and the protocol used respectively.
IndustrialLemon #7
Posted 24 April 2015 - 03:41 PM
Okay well the program is asking for another computers location so how do I send 3 variables over rednet?
KingofGamesYami #8
Posted 24 April 2015 - 03:43 PM
Send three rednet messages.

Or put them in a table, serialize the table, receive the serialized table, unserialize the table, and use the variables in the table.
Lyqyd #9
Posted 24 April 2015 - 03:47 PM
Or, in a relatively recent version of ComputerCraft (1.5+ or so), just send the table, no serialization needed.
IndustrialLemon #10
Posted 24 April 2015 - 03:49 PM
Alright I'll give the table a shot. But I have an awful history with tables.
IndustrialLemon #11
Posted 24 April 2015 - 04:02 PM
Okay. So since I'm terrible with tables and still don't fully understand them I'm gonna need to be babied a little bit.
Here's what I've got now. Problem is that it's only printing one number. Sure it's just syntax.

tx = 0
ty = 0
tz = 0
player = {px = 0, py = 0, pz = 0}
pid = 0
rednet.open("right")
tx, ty, tz = gps.locate()
print(tx.." "..ty.." "..tz)
--while true do
pid, player = rednet.receive()
print(player)
KingofGamesYami #12
Posted 24 April 2015 - 04:58 PM
Could you post the sending script?
IndustrialLemon #13
Posted 24 April 2015 - 05:25 PM
rednet.open("top")

x, y, z = gps.locate()
rednet.broadcast(x, y, z)

print(x.." "..y.." "..z)
Lupus590 #14
Posted 24 April 2015 - 06:02 PM
Okay. So since I'm terrible with tables and still don't fully understand them I'm gonna need to be babied a little bit.

this is a good start http://lua-users.org/wiki/TablesTutorial

if you have used other programming languages, tables are like arrays
Edited on 24 April 2015 - 04:03 PM
KingofGamesYami #15
Posted 24 April 2015 - 06:07 PM
Your sending script is the problem, you have to send a table, not separate variables.
IndustrialLemon #16
Posted 24 April 2015 - 07:04 PM
Oh duh, thanks guy.
IndustrialLemon #17
Posted 24 April 2015 - 07:31 PM
So, took a look at that tutorial and what I understood I knew already and what I didn't confused me. It just seems I need practice with the syntax on tables. Here's my problem now.

rednet.open("top")
player = {x = 0, y = 0, z = 0}
player["x"]["y"]["z"] = gps.locate()
rednet.broadcast(playerx, y, z)
print(player["x"]["y"]["z"])
KingofGamesYami #18
Posted 24 April 2015 - 07:40 PM

local player = {}
player.x, player.y, player.z = gps.locate()

Alternatively, you can do this:

local player = {gps.locate()}

Which would have player[ 1 ] = x, player[ 2 ] = y, player[ 3 ] = z.

Edit: What you are doing should give you "attempt to index ? (A nil value) on line 3
Edited on 24 April 2015 - 05:41 PM
KRHN #19
Posted 24 April 2015 - 07:43 PM
So, took a look at that tutorial and what I understood I knew already and what I didn't confused me. It just seems I need practice with the syntax on tables. Here's my problem now.

rednet.open("top")
player = {x = 0, y = 0, z = 0}
player["x"]["y"]["z"] = gps.locate()
rednet.broadcast(playerx, y, z)
print(player["x"]["y"]["z"])
This should be:

rednet.open("top")
player = {x = 0, y = 0, z = 0}
player["x"], player["y"], player["z"] = gps.locate()
rednet.broadcast(playerx, y, z)
print(player["x"]["y"]["z"])
Edited on 24 April 2015 - 05:44 PM
Lyqyd #20
Posted 24 April 2015 - 07:47 PM
You corrected the gps.locate line, but not the following two lines?
IndustrialLemon #21
Posted 24 April 2015 - 07:52 PM
Okay well now the reciever is the only problem. Here's the error "syntax error"

tx = 0
ty = 0
tz = 0
player = {px = 0, py = 0, pz = 0}
pid = 0
rednet.open("right")
tx, ty, tz = gps.locate()
print(tx.." "..ty.." "..tz)
--while true do
pid, player{}, blah = rednet.receive()
print(player["px"])
print(player["py"])
print(player["pz"])
Dragon53535 #22
Posted 24 April 2015 - 08:04 PM
You can't do this line:

pid, player{}, blah = rednet.receive()
That player{} is your problem. If it's a table outright being sent, then it will be a table already.


Edit: So do this:

pid, player, blah = rednet.receive()
Edited on 24 April 2015 - 06:09 PM