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

Making tArgs a string

Started by JaydenLoon3y, 22 May 2013 - 12:42 AM
JaydenLoon3y #1
Posted 22 May 2013 - 02:42 AM
Is there a way to convert tArgs to a string value?


This is a program called run which simply sends a global message of what ever program you want to run

local tArgs = {...}
rednet.broadcast(tArgs)

The other computers/turtles have this code

event,id,message = os.pullEvent(rednet_mesage)
os.run(message)

and they give this error

bois:336: Expected String, string

Any possible fixes?
Shnupbups #2
Posted 22 May 2013 - 02:46 AM
Instead of the tArgs in rednet.broadcast:
If there's only one argument, use tArgs[1]. If there can be multiple, use unpack(tArgs)

Also, use shell.run() instead of os.run(). It's easier.
JaydenLoon3y #3
Posted 22 May 2013 - 02:51 AM
Thanks! It works perfectly +1'd
KaoS #4
Posted 23 May 2013 - 02:38 AM
I think a better way is to serialize it…


local strVersion=textutils.serialize(tArgs)
rednet.broadcast(strVersion)

then once you receive the message on the other side use textutils.unserialize to convert it back
Engineer #5
Posted 23 May 2013 - 07:49 AM
Its actually up to what the purpose of this is. If this is an user based message, I would use table.concat:

local tArgs = {...}
rednet.broadcast(table.concat(tArgs, ' ')) -- open rednet first!