troubles implementing carrot

I’m trying to use carrot, first i’m following this

https://gocarrot.com/docs/corona

and this example

https://github.com/GoCarrot/carrot-corona/blob/master/Corona/menu.lua

and here’s my screen_MainMenu.lua

http://pastebin.com/CiV5GYDx

 I’m trying to integrate facebook login to an app

 

the user login to facebook, by doing so, he can share his score on facebook and also his score is saved there, so if he changed his phone, his score will score and achievements are saved. I tried to do it but the apps keep crashing when the game is done, could you help me integrate it?

 

Hey, sorry you are having troubles. Do you have any information about the crash itself? It’s hard to be certain what is going wrong with the available info.

Does the console in the simulator display any information or debug print?

sir a small question, I will send you my source code, so you can see the problem if you want, it’s here

 

first when i try to run your example it gives invalid token, is it because facebook login functionality is not supported on the simulator?

I noticed that all the work is done in menu,lua not main.lua in your github example, and that you use storyboard. I don’t use storyboard in my game,

can i create a file just for carrot? what i’m thinking is to load a facebook login image in my Screen_MainMenu.lua, when the user press on that image, he’ll be doing authentication in carrot.lua,  to load

[lua]function scene:createScene( event )

local group = self.view

– create a widget button (which will loads level1.lua on release)

playBtn = widget.newButton{

label=“Test Event”,

labelColor = { default={255}, over={128} },

defaultFile=“button.png”,

overFile=“button-over.png”,

width=154, height=40,

onRelease = onPlayBtnRelease – event listener function

}
playBtn:setReferencePoint( display.CenterReferencePoint )

playBtn.x = display.contentWidth*0.5

playBtn.y = display.contentHeight - 125

– Carrot status text

local carrotStatusText = display.newText(“Carrot Status: UNKNOWN”, 0,0, nil, 14);

carrotStatusText:setReferencePoint(display.TopLeftReferencePoint);

carrotStatusText.x = 0;

– all display objects must be inserted into group

group:insert( playBtn )

group:insert( carrotStatusText )

– Carrot
carrot.init(fbAppID, carrotAppSecret)

carrot.setStatusCallback(function(status)

carrotStatusText.text = "Carrot Status: "…status

carrotStatusText:setReferencePoint(display.TopLeftReferencePoint);

carrotStatusText.x = 0;

end)

if system.getInfo(“environment”) == “device” then

facebook.login(fbAppID, function(event)

if event.type == “session” and event.phase == “login” then

carrot.validateUser(event.token)

end
end, {“publish_actions”})

else
local debugUserToken = “<< USER TOKEN FROM ACCESS TOKEN TOOL >>”

carrot.validateUser(debugUserToken)

end
end

– Called immediately after scene has moved onscreen:

function scene:enterScene( event )

local group = self.view

– INSERT code here (e.g. start timers, load audio, start listeners, etc.)

end

– Called when scene is about to move offscreen:

function scene:exitScene( event )

local group = self.view

– INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)

end

– If scene’s view is removed, scene:destroyScene() will be called just prior to:

function scene:destroyScene( event )

local group = self.view

if playBtn then

playBtn:removeSelf() – widgets must be manually removed

playBtn = nil

end
end
[/lua]

and then when done i do

    director:changeScene( “screen_MainMenu” )

would that work? any help is highly appreciated Sir

Correct, Facebook isn’t supported in the simulator so it can’t get an access token, however this line:

local debugUserToken = "\<\< USER TOKEN FROM ACCESS TOKEN TOOL \>\>"

That can be filled in with a user token from Facebook’s Access Token Tool on their developers site: https://developers.facebook.com/tools/access_token/

Note that access tokens only work for a limited amount of time before it generates a new one. The Facebook SDK takes care of this on mobile, but you may need to cut/paste a new one for debugging.

Next, Carrot does not need to be in a scene in order to function, you can put it wherever you like. The only events that it listens to are application resume/suspend. I have not tried putting it into its own file but I see no reason why that shouldn’t work.

Hey, sorry you are having troubles. Do you have any information about the crash itself? It’s hard to be certain what is going wrong with the available info.

Does the console in the simulator display any information or debug print?

sir a small question, I will send you my source code, so you can see the problem if you want, it’s here

 

first when i try to run your example it gives invalid token, is it because facebook login functionality is not supported on the simulator?

I noticed that all the work is done in menu,lua not main.lua in your github example, and that you use storyboard. I don’t use storyboard in my game,

can i create a file just for carrot? what i’m thinking is to load a facebook login image in my Screen_MainMenu.lua, when the user press on that image, he’ll be doing authentication in carrot.lua,  to load

[lua]function scene:createScene( event )

local group = self.view

– create a widget button (which will loads level1.lua on release)

playBtn = widget.newButton{

label=“Test Event”,

labelColor = { default={255}, over={128} },

defaultFile=“button.png”,

overFile=“button-over.png”,

width=154, height=40,

onRelease = onPlayBtnRelease – event listener function

}
playBtn:setReferencePoint( display.CenterReferencePoint )

playBtn.x = display.contentWidth*0.5

playBtn.y = display.contentHeight - 125

– Carrot status text

local carrotStatusText = display.newText(“Carrot Status: UNKNOWN”, 0,0, nil, 14);

carrotStatusText:setReferencePoint(display.TopLeftReferencePoint);

carrotStatusText.x = 0;

– all display objects must be inserted into group

group:insert( playBtn )

group:insert( carrotStatusText )

– Carrot
carrot.init(fbAppID, carrotAppSecret)

carrot.setStatusCallback(function(status)

carrotStatusText.text = "Carrot Status: "…status

carrotStatusText:setReferencePoint(display.TopLeftReferencePoint);

carrotStatusText.x = 0;

end)

if system.getInfo(“environment”) == “device” then

facebook.login(fbAppID, function(event)

if event.type == “session” and event.phase == “login” then

carrot.validateUser(event.token)

end
end, {“publish_actions”})

else
local debugUserToken = “<< USER TOKEN FROM ACCESS TOKEN TOOL >>”

carrot.validateUser(debugUserToken)

end
end

– Called immediately after scene has moved onscreen:

function scene:enterScene( event )

local group = self.view

– INSERT code here (e.g. start timers, load audio, start listeners, etc.)

end

– Called when scene is about to move offscreen:

function scene:exitScene( event )

local group = self.view

– INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)

end

– If scene’s view is removed, scene:destroyScene() will be called just prior to:

function scene:destroyScene( event )

local group = self.view

if playBtn then

playBtn:removeSelf() – widgets must be manually removed

playBtn = nil

end
end
[/lua]

and then when done i do

    director:changeScene( “screen_MainMenu” )

would that work? any help is highly appreciated Sir

Correct, Facebook isn’t supported in the simulator so it can’t get an access token, however this line:

local debugUserToken = "\<\< USER TOKEN FROM ACCESS TOKEN TOOL \>\>"

That can be filled in with a user token from Facebook’s Access Token Tool on their developers site: https://developers.facebook.com/tools/access_token/

Note that access tokens only work for a limited amount of time before it generates a new one. The Facebook SDK takes care of this on mobile, but you may need to cut/paste a new one for debugging.

Next, Carrot does not need to be in a scene in order to function, you can put it wherever you like. The only events that it listens to are application resume/suspend. I have not tried putting it into its own file but I see no reason why that shouldn’t work.