# troubles implementing carrot

**URL:** <https://forums.solar2d.com/t/troubles-implementing-carrot/317642>\
**Category:** Carrot\
**Created:** [September 6, 2013, 11:22pm UTC](https://forums.solar2d.com/t/troubles-implementing-carrot/317642 "2013-09-06T23:22:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![elieobeid7](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/e/ee7513/32.png) [@elieobeid7](https://forums.solar2d.com/u/elieobeid7)\
**Post date:** [September 6, 2013, 11:22pm UTC](https://forums.solar2d.com/t/troubles-implementing-carrot/317642/1 "2013-09-06T23:22:24Z")

</div>

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

[https://gocarrot.com/docs/corona](https://gocarrot.com/docs/corona)

and this example

[https://github.com/GoCarrot/carrot-corona/blob/master/Corona/menu.lua](https://github.com/GoCarrot/carrot-corona/blob/master/Corona/menu.lua)

and here’s my&nbsp;screen\_MainMenu.lua

[http://pastebin.com/CiV5GYDx](http://pastebin.com/CiV5GYDx)

&nbsp;I’m trying to integrate facebook login to an app

&nbsp;

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?

&nbsp;

---

<div class="post-metadata">

**Author:** ![pat9](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/p/7993a0/32.png) [@pat9](https://forums.solar2d.com/u/pat9)\
**Post date:** [September 9, 2013, 7:01pm UTC](https://forums.solar2d.com/t/troubles-implementing-carrot/317642/2 "2013-09-09T19:01:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![elieobeid7](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/e/ee7513/32.png) [@elieobeid7](https://forums.solar2d.com/u/elieobeid7)\
**Post date:** [September 11, 2013, 1:06am UTC](https://forums.solar2d.com/t/troubles-implementing-carrot/317642/3 "2013-09-11T01:06:57Z")

</div>

sir a small question, I will send you my source code, so you can see the problem if you want, it’s&nbsp;[here](https://www.dropbox.com/s/2leip8d9qxts5r6/the%20game.rar)

&nbsp;

first when i try to run your example&nbsp;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](https://www.dropbox.com/s/2leip8d9qxts5r6/the%20game.rar),

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, &nbsp;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

&nbsp;&nbsp;&nbsp;&nbsp;director:changeScene( “screen\_MainMenu” )

would that work? any help is highly appreciated Sir

---

<div class="post-metadata">

**Author:** ![pat9](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/p/7993a0/32.png) [@pat9](https://forums.solar2d.com/u/pat9)\
**Post date:** [September 11, 2013, 9:33pm UTC](https://forums.solar2d.com/t/troubles-implementing-carrot/317642/4 "2013-09-11T21:33:17Z")

</div>

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:&nbsp;[https://developers.facebook.com/tools/access\_token/](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.

---

<div class="post-metadata">

**Author:** ![pat9](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/p/7993a0/32.png) [@pat9](https://forums.solar2d.com/u/pat9)\
**Post date:** [September 9, 2013, 7:01pm UTC](https://forums.solar2d.com/t/troubles-implementing-carrot/317642/5 "2013-09-09T19:01:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![elieobeid7](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/e/ee7513/32.png) [@elieobeid7](https://forums.solar2d.com/u/elieobeid7)\
**Post date:** [September 11, 2013, 1:06am UTC](https://forums.solar2d.com/t/troubles-implementing-carrot/317642/6 "2013-09-11T01:06:57Z")

</div>

sir a small question, I will send you my source code, so you can see the problem if you want, it’s&nbsp;[here](https://www.dropbox.com/s/2leip8d9qxts5r6/the%20game.rar)

&nbsp;

first when i try to run your example&nbsp;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](https://www.dropbox.com/s/2leip8d9qxts5r6/the%20game.rar),

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, &nbsp;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

&nbsp;&nbsp;&nbsp;&nbsp;director:changeScene( “screen\_MainMenu” )

would that work? any help is highly appreciated Sir

---

<div class="post-metadata">

**Author:** ![pat9](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/p/7993a0/32.png) [@pat9](https://forums.solar2d.com/u/pat9)\
**Post date:** [September 11, 2013, 9:33pm UTC](https://forums.solar2d.com/t/troubles-implementing-carrot/317642/7 "2013-09-11T21:33:17Z")

</div>

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:&nbsp;[https://developers.facebook.com/tools/access\_token/](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.
