I am using JSON:encode to prepare a lua table for udp transmition. On the other end I am using JSON.parse to to decode and then define the 3 variables. On the transmition side I verify that the table is created and has all three variables by printing botMsg[0], botMsg[1] and botMsg[3] to the logs before running JSON:encode(botMsg). On the receiving end I run obj = JSON.parse(msg) and then define the 3 variables for use in the code. What I end up with is the first variable obj[0] is botMsg[1] and obj[1] is botMsg[2] and obj[2] is undefined.
Looking for ideas why this is happening?
Transmition side LUA code:
PandaBoss.sendBossMessage = function(msg)
botMsg = {}
botMsg[1] = msg
botMsg[2] = guild_ID
botMsg[3] = channel_ID
env.info(botMsg[1]) --prints msg to data log
env.info(botMsg[2]) --prints guild_id to data log
env.info(botMsg[3]) --prints channel_id to data log
json_string = JSON:encode(botMsg)
socket.try(PandaBoss.UDPSendSocket:sendto(json_string, ip, 31090))
end
Receiving node.js code:
server.on('message', function(msg) {
obj = JSON.parse(msg)
bossMsg = obj[0]
guild_ID = obj[1]
channel_ID = obj[2]
console.log(bossMsg); //prints guild_id
console.log(guild_ID); //prints channel_id
console.log(channel_ID); //prints undefined
});
New Change to receiver
server.on('message', function(msg) {
console.log(msg.toString());
obj = JSON.parse(msg)
bossMsg = obj[0]
guild_ID = obj[1]
channel_ID = obj[2]
console.log(bossMsg);
console.log(guild_ID);
console.log(channel_ID);
});