20 posts
Posted 04 August 2012 - 01:33 AM
How would i define my own events in LUA and is it possible to do in computercraft?
I have been trying to make a world chat system, with custom logic for both send and receive functions, but I need a way to define a custome rednet_message event with more than 3 parameters.
Thanks,
~Matt
127 posts
Posted 04 August 2012 - 04:31 AM
From what i understand from that is you want to send multiple things in the one rednet message? if so try sending as message textutils.serialize({value/string1,and so on,and so on } ) and then on the reieving computer do result = textutils.unserialize(messageparamofrednet) then to call each part of the result do result[1] and so on and so forth
1111 posts
Location
Portland OR
Posted 04 August 2012 - 05:06 AM
I haven't really played with this and I'm at work so I'm not going to be able to give you a working example. But you could queue your own events with..
os.queueEvent( event, param1, param2, param3, and so on.... )
You will probably want to call it something other then rednet_message just to try and avoid having any issues with the original event.
20 posts
Posted 05 August 2012 - 01:07 AM
From what i understand from that is you want to send multiple things in the one rednet message? if so try sending as message textutils.serialize({value/string1,and so on,and so on } ) and then on the reieving computer do result = textutils.unserialize(messageparamofrednet) then to call each part of the result do result[1] and so on and so forth
I can't quite seem to get the data out of the unserialization. The textutils.serialize(blah,blah,blah,blah) works fine.
local e, p1, p2, p3 = os.pullEvent()
if e == "rednet_message" then
local result = textutils.unserialize(p2)
result[1] = senderName
result[2] = senderMessage
result[3] = messageType
result[4] = sendCount
print(senderName..": "..senderMessage)
I error on the print() line. the error says "attempting to concatenate string and nil." so why am i not getting data out of the result?
1604 posts
Posted 05 August 2012 - 01:16 AM
You'r overwriting the values on the table, instead of assigning them to the variables. It should be:
senderName = result[1]
senderMessage = result[2]
messageType = result[3]
sendCount = result[4]
20 posts
Posted 05 August 2012 - 01:17 AM
Haha thanks, I just went back to debug my code and I felt really really stupid.