I have tried now to get a variable out of a socket.on();
but can't get it out as it says it is an undefined variable.
Here is the code bit that doesn't work:
io.on('connection', function(socket){
socket.join("0");
socket.on("chatroom",function(chat){
socket.join(chat);
if(chat != "0"){
console.log("A user joined chatroom: " + chat);
}
var chatroom = chat;
});
});
var chatroom = chatroom;
As you see it is the variable above that get's a value of undefined even if it has a value of 2 in the io.on fuction. Any ideas how to get it out?
Excuse me for my noobish codes (only 3 days experience in node.js)