如何在电晕中调用此代码中发送电子邮件的功能?

时间:2014-02-26 23:26:16

标签: lua corona

以下是我正在撰写的简单游戏代码的一部分,我正在尝试发送一封电子邮件,其中包含用户在菜单屏幕上花费的时间。我不知道在哪里调用选项功能。

--Send a email to my own address
local options =
{
to = "richard@gmail.com",
subject = "Time spent at the menu screen",
body = "This is the time I spent to look at the menu"..(os.time() - startTime),
}
native.showPopup("mail", options)

--Function that initializes all game logic
function Main()
splash:removeSelf()
splash = nil

playGame = display.newImage("Play Button.png")
tutorial = display.newImage("Tutorial Button.png")
credits = display.newImage("Credits Button.png")

playGame.x = display.contentWidth / 2
playGame.y = display.contentWidth - 187
tutorial.x = display.contentWidth / 2
tutorial.y = display.contentWidth - 130
credits.x = display.contentWidth / 2
credits.y = display.contentWidth - 73

startButtonListeners('add')
end

--Adds listeners to the button in menu screen
function startButtonListeners(action)
    if (action == 'add') then
          playGame:addEventListener ('tap', showGameView)
          credits: addEventListener ('tap', showCredits)
          tutorial: addEventListener ("tap", showTutorial)
    else 
        playGame:removeEventListener ('tap', showGameView)
        print("Time spent at menu screen: ", (os.time() - startTime))
        credits: removeEventListener ('tap', showCredits)
        tutorial: removeEventListener ('tap', showTutorial)
          end
end

1 个答案:

答案 0 :(得分:2)

我无法完全理解你的需要。我想,当你离开屏幕或游戏结束时,你必须发送电子邮件到一个特定的地址。因此,当您的游戏结束时,或者当您通过触发按钮离开屏幕时,您可以在其中调用options的函数。如下所示:

local function sendMail()
   local options =
   {
     to = "richard@gmail.com",
     subject = "Time spent at the menu screen",
     body = "This is the time I spent to look at the menu"..(os.time() - startTime),
    }
    native.showPopup("mail", options)
end

...
...
...
sendMail()  -- Call this when the game is over/before you leave the scene

有关详细信息,请参阅此链接:How to mail a screen captured image using corona SDK

保持编码.............:)