the Social Plugin to share score ( Numbers )

Hi i am using the the Social Plugin to share my app on android, and it works with most of installed program sharing message , URL and also the image of my app,

but i cant make it work to share the score of the player

the scores is stored in the doc directory using json .

and when i try to add the score to the MSG , it game me err like you are trying to add number to str , i tried also to convert the numbers to str using toString()  but still not working

here is the func

 local ScoreToShareNO = myData.settings.HighScore local StarsToShareNO = myData.settings.levels.stars local ScoreToShareStr= tostring(ScoreToShareNO) local StarsToShareStr= tostring(StarsToShareNO) local function onShareButtonReleased( event ) local serviceName = event.target.id local isAvailable = native.canShowPopup( popupName, serviceName ) -- For demonstration purposes, we set isAvailable to true here for Android. if "Android" == system.getInfo( "platformName" ) then isAvailable = true end -- If it is possible to show the popup if isAvailable then local listener = {} function listener:popup( event ) print( "name(" .. event.name .. ") type(" .. event.type .. ") action(" .. tostring(event.action) .. ") limitReached(" .. tostring(event.limitReached) .. ")" ) end local options = {} options.service = serviceName options.listener = listener if sendMessage then options.message = {("Share this game your friends!, and check my Score"),StarsToShareStr,ScoreToShareStr} end if sendURL then options.url = { "http://www.coronalabs.com" } end if sendImage then options.image = { { filename = "Icon-xhdpi.png", baseDir = system.ResourceDirectory }, } end --sceneGroup:insert(options) -- Show the popup native.showPopup( popupName, options ) else if isSimulator then native.showAlert( "Build for device", "This plugin is not supported on the Corona Simulator, please build for an iOS/Android device or the Xcode simulator", { "OK" } ) else -- Popup isn't available.. Show error message native.showAlert( "Cannot send " .. serviceName .. " message.", "Please setup your " .. serviceName .. " account or check your network connection (on android this means that the package/app (ie Twitter) is not installed on the device)", { "OK" } ) end end end

i tried so many combinations but i couldn’t get it work

if sendMessage then     options.message = {("Share this game your friends!, and check my Score"),StarsToShareStr,ScoreToShareStr} end

should be:

if sendMessage then     options.message = { "Share this game your friends!, and check my Stars: " .. StarsToShareStr .. " and Score: " ..  ScoreToShareStr } end

Rob

Thanks Rob

but this didn’t work . it didn’t give err , but it didn’t share the score , and even it completely ignored the whole message

i used print to print the StarsToShareStr and it printing the StarsToShareStr to the terminal

but when i try to share the message , it didn’t show any thing

Can you show the code around where you are setting the value of “sendMessage”?

acualy i change the code a bit becuase i dont want to have all that share buttons ( fb,twitter,etc ) as this will be for android so i just edit and use the function as tap listener for shareButton in the main menu

local function onShareButtonReleased( event ) local serviceName = event.target.id local isAvailable = native.canShowPopup( popupName, serviceName ) local options = {} options.service = serviceName options.listener = listener options.message = { "Share this game your friends!, and check my Stars: " .. StarsToShareStr .. " and Score: " .. ScoreToShareStr } options.url = { "http://www.coronalabs.com" } options.image = { { filename = "Icon-xhdpi.png", baseDir = system.ResourceDirectory }, } native.showPopup( popupName, options ) print(ScoreToShareStr) end 

if i only used

options.message = "Share this game your friends!, and check my Stars: "

then it show this message and share it , but if i added the above one . it didnot show any thing , instead i can print the score and the stars to the terminal without issue

i already declared and get the stars and the sore using myData File and add it just after the create Scene Function , and it works fine when i print it

myData.settings = loadsave.loadTable( "settings.json" ) local ScoreToShareNO = myData.settings.HighScore local StarsToShareNO = myData.settings.levels local ScoreToShareStr= tostring(ScoreToShareNO) local StarsToShareStr= tostring(StarsToShareNO)

Are you getting an error?

You can also put in some print statements in to check the values of what you’re expecting. You can use a table printing function (see: to print out myData.settings to make sure of what you’re actually reading from.

Rob

Yes Rob the

print(ScoreToShareStr)

in the above function prints exactly what Score is in the MyData File , and there is no err , i used also the debugger in my android device and i didnot get any err

Well without seeing more code, and looking at your local variables being indented, are they inside some other function or re they sitting at the top in the scene’s main chunk?

If they are in another function, you could have a scope issue…

Rob

Hey Rob , here is the entire Menu Lua file

local composer = require( "composer" ) local scene = composer.newScene() local myData = require( "mydata" ) local json = require( "json" ) local loadsave = require( "loadsave" ) display.setStatusBar(display.HiddenStatusBar) ads = require( "ads" ) local MainMusicGameMenu = audio.loadStream ("Main.ogg") local widget = require( "widget" ) local popupName = "social" -- -------------------------------------k---------------------------------------------------------------------------- -- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called. -- ----------------------------------------------------------------------------------------------------------------- local PlayGameButton local CreditsButton local SettingsButton local WriteScoreTemp local WriteScore local score local options = { effect = "fade", time = 100, } local centerX = display.contentCenterX local centerY = display.contentCenterY local screenLeft = display.screenOriginX local screenWidth = display.contentWidth - screenLeft \* 2 local screenRight = screenLeft + screenWidth local screenTop = display.screenOriginY local screenHeight = display.contentHeight - screenTop \* 2 local screenBottom = screenTop + screenHeight local sequences\_animatedSettings = { -- consecutive frames sequence { name = "Grey", frames = {1,2}, time = 4000, loopCount = 1, loopDirection = "forward" }, } local sheetOptionsSettings = { width = 154, height = 50, numFrames = 2 } local sequences\_animatedCredits = { -- consecutive frames sequence { name = "Grey", frames = {1,2}, time = 3000, loopCount = 1, loopDirection = "forward" }, } local sheetOptionsCredits = { width = 170, height = 55, numFrames = 2 } local sequences\_animatedPlay = { -- consecutive frames sequence { name = "Grey", frames = {1,2}, time = 2000, loopCount = 0, loopDirection = "forward" }, } local sheetOptionsPlay = { width = 170, height = 90, numFrames = 2 } local function PlayGameButtonF (event) composer.gotoScene ("levelselect", options) return true -- body end local function CreditsButtonF (event) composer.gotoScene ("Credits", {effect="slideDown"}) return true -- bodyر end local function SettingsButtonF (event) composer.gotoScene ("Settings", {effect="slideUp"}) return true -- body end -- ------------------------------------------------------------------------------- -- "scene:create()" function scene:create( event ) local sceneGroup = self.view local widget = require( "widget" ) -- Use the iOS 7 theme for this sample widget.setTheme( "widget\_theme\_ios7" ) -- This is the name of the native popup to show, in this case we are showing the "social" popup local popupName = "social" local myData = require( "mydata" ) -- Initialize the scene here. -- Example: add display to "sceneGroup", add touch listeners, etc. score = 0 myData.settings = loadsave.loadTable( "settings.json" ) local ScoreToShareNO = myData.settings.HighScore local StarsToShareNO = myData.settings.levels local ScoreToShareStr= tostring(ScoreToShareNO) local StarsToShareStr= tostring(StarsToShareNO) local background1 = display.newImage (sceneGroup,"Menu3.jpg") background1.x = centerX background1.y = centerY-10 background1:toBack(); local sheet\_animatedPlay = graphics.newImageSheet( "PlayGlow.png", sheetOptionsPlay ) local PlayGameButton = display.newSprite( sheet\_animatedPlay, sequences\_animatedPlay ); PlayGameButton.x=centerX PlayGameButton.y=centerY+10 PlayGameButton:play() sceneGroup:insert(PlayGameButton) PlayGameButton:addEventListener("tap", PlayGameButtonF ) local sheet\_animatedSettings = graphics.newImageSheet( "SettingGlow.png", sheetOptionsSettings ) local SettingsButton = display.newSprite( sheet\_animatedSettings, sequences\_animatedSettings ); SettingsButton.x=centerX SettingsButton.y=centerY+80 --SettingsButton:play() sceneGroup:insert(SettingsButton) SettingsButton:addEventListener("tap", SettingsButtonF ) local sheet\_animatedCredits = graphics.newImageSheet( "CreditsGlow.png", sheetOptionsCredits ) local SettingsButton = display.newSprite( sheet\_animatedCredits, sequences\_animatedCredits ); SettingsButton.x=centerX SettingsButton.y=centerY+140 sceneGroup:insert(SettingsButton) SettingsButton:addEventListener("tap", CreditsButtonF ) local function onShareButtonReleased( event ) local serviceName = event.target.id local isAvailable = native.canShowPopup( popupName, serviceName ) local options = {} options.service = serviceName options.listener = listener options.message = { "Share this game your friends!, and check my Stars: " .. StarsToShareStr .. " and Score: " .. ScoreToShareStr } options.url = { "http://www.coronalabs.com" } options.image = { { filename = "Icon-xhdpi.png", baseDir = system.ResourceDirectory }, } native.showPopup( popupName, options ) print(ScoreToShareStr) end local ShareOnly = display.newImage (sceneGroup,"share.png") ShareOnly.x = centerX+10 ShareOnly.y = centerY+210 ShareOnly:addEventListener("tap", onShareButtonReleased) end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then if audio.isChannelPaused( 1 ) then audio.resume( { channel=1} ) end if myData.settings.musicOn == true then playMusic = audio.play (MainMusicGameMenu, { channel=1, loops=-1, fadein=3000 } ) elseif myData.settings.musicOn == false then end -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view --audio.pause() -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display , save state, etc. --sceneGroup.remove(PlayGameButton) --sceneGroup.remove(CreditsButton) --sceneGroup.remove(SettingsButton) --composer.removeScene("menu",true) end -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene
if sendMessage then     options.message = {("Share this game your friends!, and check my Score"),StarsToShareStr,ScoreToShareStr} end

should be:

if sendMessage then     options.message = { "Share this game your friends!, and check my Stars: " .. StarsToShareStr .. " and Score: " ..  ScoreToShareStr } end

Rob

Thanks Rob

but this didn’t work . it didn’t give err , but it didn’t share the score , and even it completely ignored the whole message

i used print to print the StarsToShareStr and it printing the StarsToShareStr to the terminal

but when i try to share the message , it didn’t show any thing

Can you show the code around where you are setting the value of “sendMessage”?

acualy i change the code a bit becuase i dont want to have all that share buttons ( fb,twitter,etc ) as this will be for android so i just edit and use the function as tap listener for shareButton in the main menu

local function onShareButtonReleased( event ) local serviceName = event.target.id local isAvailable = native.canShowPopup( popupName, serviceName ) local options = {} options.service = serviceName options.listener = listener options.message = { "Share this game your friends!, and check my Stars: " .. StarsToShareStr .. " and Score: " .. ScoreToShareStr } options.url = { "http://www.coronalabs.com" } options.image = { { filename = "Icon-xhdpi.png", baseDir = system.ResourceDirectory }, } native.showPopup( popupName, options ) print(ScoreToShareStr) end 

if i only used

options.message = "Share this game your friends!, and check my Stars: "

then it show this message and share it , but if i added the above one . it didnot show any thing , instead i can print the score and the stars to the terminal without issue

i already declared and get the stars and the sore using myData File and add it just after the create Scene Function , and it works fine when i print it

myData.settings = loadsave.loadTable( "settings.json" ) local ScoreToShareNO = myData.settings.HighScore local StarsToShareNO = myData.settings.levels local ScoreToShareStr= tostring(ScoreToShareNO) local StarsToShareStr= tostring(StarsToShareNO)

Are you getting an error?

You can also put in some print statements in to check the values of what you’re expecting. You can use a table printing function (see: to print out myData.settings to make sure of what you’re actually reading from.

Rob

Yes Rob the

print(ScoreToShareStr)

in the above function prints exactly what Score is in the MyData File , and there is no err , i used also the debugger in my android device and i didnot get any err

Well without seeing more code, and looking at your local variables being indented, are they inside some other function or re they sitting at the top in the scene’s main chunk?

If they are in another function, you could have a scope issue…

Rob

Hey Rob , here is the entire Menu Lua file

local composer = require( "composer" ) local scene = composer.newScene() local myData = require( "mydata" ) local json = require( "json" ) local loadsave = require( "loadsave" ) display.setStatusBar(display.HiddenStatusBar) ads = require( "ads" ) local MainMusicGameMenu = audio.loadStream ("Main.ogg") local widget = require( "widget" ) local popupName = "social" -- -------------------------------------k---------------------------------------------------------------------------- -- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called. -- ----------------------------------------------------------------------------------------------------------------- local PlayGameButton local CreditsButton local SettingsButton local WriteScoreTemp local WriteScore local score local options = { effect = "fade", time = 100, } local centerX = display.contentCenterX local centerY = display.contentCenterY local screenLeft = display.screenOriginX local screenWidth = display.contentWidth - screenLeft \* 2 local screenRight = screenLeft + screenWidth local screenTop = display.screenOriginY local screenHeight = display.contentHeight - screenTop \* 2 local screenBottom = screenTop + screenHeight local sequences\_animatedSettings = { -- consecutive frames sequence { name = "Grey", frames = {1,2}, time = 4000, loopCount = 1, loopDirection = "forward" }, } local sheetOptionsSettings = { width = 154, height = 50, numFrames = 2 } local sequences\_animatedCredits = { -- consecutive frames sequence { name = "Grey", frames = {1,2}, time = 3000, loopCount = 1, loopDirection = "forward" }, } local sheetOptionsCredits = { width = 170, height = 55, numFrames = 2 } local sequences\_animatedPlay = { -- consecutive frames sequence { name = "Grey", frames = {1,2}, time = 2000, loopCount = 0, loopDirection = "forward" }, } local sheetOptionsPlay = { width = 170, height = 90, numFrames = 2 } local function PlayGameButtonF (event) composer.gotoScene ("levelselect", options) return true -- body end local function CreditsButtonF (event) composer.gotoScene ("Credits", {effect="slideDown"}) return true -- bodyر end local function SettingsButtonF (event) composer.gotoScene ("Settings", {effect="slideUp"}) return true -- body end -- ------------------------------------------------------------------------------- -- "scene:create()" function scene:create( event ) local sceneGroup = self.view local widget = require( "widget" ) -- Use the iOS 7 theme for this sample widget.setTheme( "widget\_theme\_ios7" ) -- This is the name of the native popup to show, in this case we are showing the "social" popup local popupName = "social" local myData = require( "mydata" ) -- Initialize the scene here. -- Example: add display to "sceneGroup", add touch listeners, etc. score = 0 myData.settings = loadsave.loadTable( "settings.json" ) local ScoreToShareNO = myData.settings.HighScore local StarsToShareNO = myData.settings.levels local ScoreToShareStr= tostring(ScoreToShareNO) local StarsToShareStr= tostring(StarsToShareNO) local background1 = display.newImage (sceneGroup,"Menu3.jpg") background1.x = centerX background1.y = centerY-10 background1:toBack(); local sheet\_animatedPlay = graphics.newImageSheet( "PlayGlow.png", sheetOptionsPlay ) local PlayGameButton = display.newSprite( sheet\_animatedPlay, sequences\_animatedPlay ); PlayGameButton.x=centerX PlayGameButton.y=centerY+10 PlayGameButton:play() sceneGroup:insert(PlayGameButton) PlayGameButton:addEventListener("tap", PlayGameButtonF ) local sheet\_animatedSettings = graphics.newImageSheet( "SettingGlow.png", sheetOptionsSettings ) local SettingsButton = display.newSprite( sheet\_animatedSettings, sequences\_animatedSettings ); SettingsButton.x=centerX SettingsButton.y=centerY+80 --SettingsButton:play() sceneGroup:insert(SettingsButton) SettingsButton:addEventListener("tap", SettingsButtonF ) local sheet\_animatedCredits = graphics.newImageSheet( "CreditsGlow.png", sheetOptionsCredits ) local SettingsButton = display.newSprite( sheet\_animatedCredits, sequences\_animatedCredits ); SettingsButton.x=centerX SettingsButton.y=centerY+140 sceneGroup:insert(SettingsButton) SettingsButton:addEventListener("tap", CreditsButtonF ) local function onShareButtonReleased( event ) local serviceName = event.target.id local isAvailable = native.canShowPopup( popupName, serviceName ) local options = {} options.service = serviceName options.listener = listener options.message = { "Share this game your friends!, and check my Stars: " .. StarsToShareStr .. " and Score: " .. ScoreToShareStr } options.url = { "http://www.coronalabs.com" } options.image = { { filename = "Icon-xhdpi.png", baseDir = system.ResourceDirectory }, } native.showPopup( popupName, options ) print(ScoreToShareStr) end local ShareOnly = display.newImage (sceneGroup,"share.png") ShareOnly.x = centerX+10 ShareOnly.y = centerY+210 ShareOnly:addEventListener("tap", onShareButtonReleased) end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then if audio.isChannelPaused( 1 ) then audio.resume( { channel=1} ) end if myData.settings.musicOn == true then playMusic = audio.play (MainMusicGameMenu, { channel=1, loops=-1, fadein=3000 } ) elseif myData.settings.musicOn == false then end -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view --audio.pause() -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display , save state, etc. --sceneGroup.remove(PlayGameButton) --sceneGroup.remove(CreditsButton) --sceneGroup.remove(SettingsButton) --composer.removeScene("menu",true) end -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene