60 posts
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)
957 posts
Location
Web Development
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?
7083 posts
Location
Tasmania (AU)
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)
10 posts
Location
Turkey
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
72 posts
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
756 posts
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.
60 posts
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?
3057 posts
Location
United States of America
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.
8543 posts
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.
60 posts
Posted 24 April 2015 - 03:49 PM
Alright I'll give the table a shot. But I have an awful history with tables.
60 posts
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)
3057 posts
Location
United States of America
Posted 24 April 2015 - 04:58 PM
Could you post the sending script?
60 posts
Posted 24 April 2015 - 05:25 PM
rednet.open("top")
x, y, z = gps.locate()
rednet.broadcast(x, y, z)
print(x.." "..y.." "..z)
2427 posts
Location
UK
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/TablesTutorialif you have used other programming languages, tables are
like arrays
Edited on 24 April 2015 - 04:03 PM
3057 posts
Location
United States of America
Posted 24 April 2015 - 06:07 PM
Your sending script is the problem, you have to send a table, not separate variables.
60 posts
Posted 24 April 2015 - 07:04 PM
Oh duh, thanks guy.
60 posts
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"])
3057 posts
Location
United States of America
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
10 posts
Location
Turkey
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
8543 posts
Posted 24 April 2015 - 07:47 PM
You corrected the gps.locate line, but not the following two lines?
60 posts
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"])
1080 posts
Location
In the Matrix
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