【问题标题】:Using pubnub with corona sdk - basic configuration使用带有 corona sdk 的 pubnub - 基本配置
【发布时间】:2014-08-21 08:39:16
【问题描述】:

我使用 corona sdk 已经有一段时间了,想开始用我的多用户应用程序实现 pubnub。

我下载了 lua-master zip 文件并将其解压缩。我需要在我的 corona 应用程序目录中使用哪些文件和文件夹才能开始测试? - 谢谢

【问题讨论】:

    标签: coronasdk pubnub


    【解决方案1】:

    PubNub Corona Lua SDK

    通过访问开始: https://github.com/pubnub/lua/tree/master/corona

    用于构建和扩展多人移动游戏的 PubNub 数据流网络。游戏状态变化、玩家移动、位置感知和监控。

    请务必将 "pubnub.lua" 复制到您的项目目录中,

    并查看3.3目录中的示例代码以获得完整的代码示例!

    pubnub.lua -> https://github.com/pubnub/lua/blob/master/corona/pubnub.lua

    初始化

    require "pubnub"
    
    multiplayer = pubnub.new({
        publish_key   = "demo",             -- YOUR PUBLISH KEY
        subscribe_key = "demo",             -- YOUR SUBSCRIBE KEY
        secret_key    = nil,                -- YOUR SECRET KEY
        ssl           = nil,                -- ENABLE SSL?
        origin        = "pubsub.pubnub.com" -- PUBNUB CLOUD ORIGIN
    })
    

    发布

    multiplayer:publish({
        channel  = "lua-corona-demo-channel",
        message  = { "1234", 2, 3, 4 },
        callback = function(info)
    
            -- WAS MESSAGE DELIVERED?
            if info[1] then
                print("MESSAGE DELIVERED SUCCESSFULLY!")
            else
                print("MESSAGE FAILED BECAUSE -> " .. info[2])
            end
    
        end
    })
    

    订阅

    multiplayer:subscribe({
        channel  = "lua-corona-demo-channel",
        callback = function(message)
            -- MESSAGE RECEIVED!!!
            print(Json.Encode(message))
        end,
        errorback = function()
            print("Network Connection Lost")
        end
    })
    

    退订

    multiplayer:unsubscribe({
        channel = "lua-corona-demo-channel"
    })
    

    历史

    function detailedHistory(channel, count, reverse)
        pubnub_obj:detailedHistory({
            channel = channel,
            count = count,
            reverse = reverse,
            callback = function(response)
                if response then
                    for k, v in pairs(response[1])
                        do
                        print( type (v) )
                        if (type (v) == 'string')
                        then print(v)
                        elseif (type (v) == 'table')
                        then
                            for i,line in ipairs(v) do
                                print(line)
                            end
                        end
                    end
                end
    
            end
        })
    end
    
    local my_channel = 'hello_world'
    detailedHistory( my_channel, 5, false )
    

    【讨论】:

    • 谢谢!最初在 lua-master.zip 中缺少一些文件,但已解决。我有一个包含上述元素的程序,但要简单得多,但我无法在 pubnub 控制台中接收消息。我不知道它是 Android 还是 Corona 特定的。我已经就该问题提出了另一个问题。 - 再次感谢。
    • 随时欢迎您,并记得查看我们的其他 SDK 和开发人员资源,用于 PubNub 和实时多人游戏开发实时软件开发资源pubnub.com/developers
    猜你喜欢
    • 2014-10-23
    • 1970-01-01
    • 2012-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-18
    • 2015-05-12
    • 1970-01-01
    相关资源
    最近更新 更多