PubNub unsubscribe issue

Hi all,

I’m currently developing online turn based game. I use PubNub for cloud system.

Here is the problem:

require "pubnub"  
  
multiplayerServer = pubnub.new({  
 publish\_key = "publish\_key", -- YOUR PUBLISH KEY  
 subscribe\_key = "subscribe\_key", -- YOUR SUBSCRIBE KEY  
 secret\_key = "secret\_key", -- YOUR SECRET KEY  
 ssl = nil, -- ENABLE SSL?  
 origin = "pubsub.pubnub.com" -- PUBNUB CLOUD ORIGIN  
})  
  
multiplayerServer:subscribe({  
 channel = "testChannel",  
 callback = function(message)   
 print(Json.Encode(message) .. " - 1")  
 end,  
 errorback = function()  
 print("Network Connection Lost")  
 end  
})  
  
multiplayerServer:unsubscribe({channel = "testChannel"})  
  
multiplayerServer:subscribe({  
 channel = "testChannel",  
 callback = function(message)   
 print(Json.Encode(message) .. " - 2")  
 end,  
 errorback = function()  
 print("Network Connection Lost")  
 end  
})  

As you see in the first callback method " - 1" is added to end of the message and in the second callback method " - 2" is added to end of the message.

When I send a message from the console this what I’ve got:

{"text":"hey"} - 1 {"text":"hey"} - 2

Isn’t this a problem? When I unsubscribe PubNub doesn’t forget the old callback function.

Any ideas? [import]uid: 5629 topic_id: 24509 reply_id: 324509[/import]

Hi yagizgurgul!

You are asking about using the Unsubscribe function correctly in the PubNub Lua API http://www.pubnub.com/game/multiplayer-gaming-iphone-lua-corona-sdk I have a quick tip for you to get this working. Here it is: You are unsubscribing and subscribing to the same channel too quickly. In order to properly use the unsubscribe function in the Lua API, you must ensure that you are not connecting/disconnecting to the same channel. For example, the correct way is to follow this pattern:
Good:

Subscribe Channel “A”, Unsubscribe Channel “A”, Subscribe Channel “B”.

Not Good:

Subscribe Channel “A”, Unsubscribe Channel “A”, Subscribe Channel “A”. [import]uid: 27840 topic_id: 24509 reply_id: 99432[/import]