object:setFillColor = (0,0,0) HAULTS PROGRAM

ISSUE 1
WHEN I UNCOMMENT “bankText:setFillColor = (0,0,0)” THE PROGRAM CHOKES!
The “bank” is the player’s current money

function showBank() local textOptions = { text = "testing", x = 5, y = 10, width = 128, --height = 0, font = native.systemFont, fontSize = 24, align = "left" } local bankText = display.newText(textOptions) bankText.anchorX = 0 bankText.anchorY = 0 bankText:setFillColor(0,0,0) --bankText:setFillColor = (0,0,0) --ERROR FIXED --sceneGroup:insert(bankText) --ERROR NOT FIXED end function tick() showBank() end function scene:didEnter( event ) local sceneGroup = self.view Runtime:addEventListener( "enterFrame", tick ) end

You have a syntax error:

bankText:setFillColor(0, 0, 0)

Is correct.

  • Caleb

Thanks, Caleb.

I can not seem to insert the text object ‘bankText’ in the sceneGroup.

When I uncomment that line, the program hangs itself.

What have I done wrong, here?

Weirdness, this seems straight forward to me.

Chris

Strangely enough, it works at first, but, when I leave the scene and come back to it, it says it is nil.

I was actually able to transition between the two scenes a few times, then the program would halt.

I thought I had to add:

 local sceneGroup = self.view  

 To the function but that caused an error as well.

Yikes, this stuff is touchy! 

:slight_smile:

Chris

Actually, I have found that I may transition between two scenes, over and over fine, but then when I transition to a third scene, and back to the playGUI, it hangs up.

I will have to check in the third module I guess, any ideas?

I’m looking.

Chris

At the time of your function running, sceneGroup doesn’t exist because it’s local to the function. You need to insert the text from a scope in which sceneGroup exists.

For example, your showBank() function could return the text object when it’s done:

return bankText

Then, in your enter scene function, call the function and insert it, or you could create one instance of bankText, localized in the top of your file, and set the text of it rather than create a new one when you use showBank().

In fact, the last option would be better, because you’re using the same bankText.

  • Caleb

Cool, Caleb, let me absorb all that. 

Thanks again.

Chris:)

Caleb, 

I am using Roaming Gamer’s sceneTemplate.

Here is the playGUI module where I am having the sceneGroup issue.

-- ============================================================= -- Play GUI -- ============================================================= local composer = require( "composer" ) local scene = composer.newScene( ---------------------------------------------------------------------- --LOCALS ---------------------------------------------------------------------- -- Variables local w = display.contentWidth local h = display.contentHeight local centerX = display.contentCenterX local centerY = display.contentCenterY -- Forward Declarations local onBack local theBank = 0 local bankText = "" ---------------------------------------------------------------------- -- Scene Methods ---------------------------------------------------------------------- --THIS IS MY CODE HERE CALEB function showBank() local textOptions = { text = theBank, x = 5, y = 10, width = 128, --height = 0, font = "charlemagne std", fontSize = 30, align = "left" } local bankText = display.newEmbossedText(textOptions) bankText:setFillColor( 0, 0, 0 ) local color = { highlight = { r=1, g=1, b=1 }, shadow = { r=1, g=1, b=1 } } bankText:setEmbossColor( color ) bankText.anchorX = 0 bankText.anchorY = 0 --sceneGroup:insert(bankText) end function tick() showBank() end --MY CODE ENDS HERE CALEB except for the call to the --Runtime:addEventListener( "enterFrame", tick ) in did enter. --Can you show me where to RETURN the bankText? ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:create( event ) local sceneGroup = self.view local back = display.newImageRect( sceneGroup, "images/BGgameTable.png", 2048, 2048 ) back.x = centerX back.y = centerY --if(w\>h) then back.rotation = 90 end -- Create a button local push1 = PushButton( sceneGroup, centerX + 400, centerY + 350, "Menu", onBack, { labelColor = {0.8,0.2,0.2}, labelSize = 18 } ) end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:willEnter( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:didEnter( event ) local sceneGroup = self.view Runtime:addEventListener( "enterFrame", tick ) end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:willExit( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:didExit( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:destroy( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- -- FUNCTION/CALLBACK DEFINITIONS -- ---------------------------------------------------------------------- onBack = function ( self, event ) local options = { effect = "fromTop", -- See list here: http://docs.coronalabs.com/daily/api/library/composer/gotoScene.html time = 500, params = { arg1 = "value", arg2 = 0 } } composer.gotoScene( "ifc.mainMenu", options ) return true end --------------------------------------------------------------------------------- -- Scene Dispatch Events, Etc. - Generally Do Not Touch Below This Line --------------------------------------------------------------------------------- function scene:show( event ) sceneGroup = self.view local willDid = event.phase if( willDid == "will" ) then self:willEnter( event ) elseif( willDid == "did" ) then self:didEnter( event ) end end function scene:hide( event ) sceneGroup = self.view local willDid = event.phase if( willDid == "will" ) then self:willExit( event ) elseif( willDid == "did" ) then self:didExit( event ) end end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene 

 I really do not like asking these questions, I feel as though I should know more than I do.

I bet you can “blaze-read” through the above code like an action novel!

:slight_smile:

Thanks, Caleb.

In this case, using a plain localized variable would be better than returning it from a function.

When you localize an object (like “local bankText”), you set it to something by assigning it without local.

So:

local bankText -- Yada, Yada, Yada... bankText = ... -- Set it to display.newText(...) however you do that

Also, if you’re using bankText to display a score or similar, you should just create it once, then, when tick() is called, update its text instead of re-creating it.

  • Caleb

You have a syntax error:

bankText:setFillColor(0, 0, 0)

Is correct.

  • Caleb

Thanks, Caleb.

I can not seem to insert the text object ‘bankText’ in the sceneGroup.

When I uncomment that line, the program hangs itself.

What have I done wrong, here?

Weirdness, this seems straight forward to me.

Chris

Strangely enough, it works at first, but, when I leave the scene and come back to it, it says it is nil.

I was actually able to transition between the two scenes a few times, then the program would halt.

I thought I had to add:

 local sceneGroup = self.view  

 To the function but that caused an error as well.

Yikes, this stuff is touchy! 

:slight_smile:

Chris

Actually, I have found that I may transition between two scenes, over and over fine, but then when I transition to a third scene, and back to the playGUI, it hangs up.

I will have to check in the third module I guess, any ideas?

I’m looking.

Chris

At the time of your function running, sceneGroup doesn’t exist because it’s local to the function. You need to insert the text from a scope in which sceneGroup exists.

For example, your showBank() function could return the text object when it’s done:

return bankText

Then, in your enter scene function, call the function and insert it, or you could create one instance of bankText, localized in the top of your file, and set the text of it rather than create a new one when you use showBank().

In fact, the last option would be better, because you’re using the same bankText.

  • Caleb

Cool, Caleb, let me absorb all that. 

Thanks again.

Chris:)

Caleb, 

I am using Roaming Gamer’s sceneTemplate.

Here is the playGUI module where I am having the sceneGroup issue.

-- ============================================================= -- Play GUI -- ============================================================= local composer = require( "composer" ) local scene = composer.newScene( ---------------------------------------------------------------------- --LOCALS ---------------------------------------------------------------------- -- Variables local w = display.contentWidth local h = display.contentHeight local centerX = display.contentCenterX local centerY = display.contentCenterY -- Forward Declarations local onBack local theBank = 0 local bankText = "" ---------------------------------------------------------------------- -- Scene Methods ---------------------------------------------------------------------- --THIS IS MY CODE HERE CALEB function showBank() local textOptions = { text = theBank, x = 5, y = 10, width = 128, --height = 0, font = "charlemagne std", fontSize = 30, align = "left" } local bankText = display.newEmbossedText(textOptions) bankText:setFillColor( 0, 0, 0 ) local color = { highlight = { r=1, g=1, b=1 }, shadow = { r=1, g=1, b=1 } } bankText:setEmbossColor( color ) bankText.anchorX = 0 bankText.anchorY = 0 --sceneGroup:insert(bankText) end function tick() showBank() end --MY CODE ENDS HERE CALEB except for the call to the --Runtime:addEventListener( "enterFrame", tick ) in did enter. --Can you show me where to RETURN the bankText? ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:create( event ) local sceneGroup = self.view local back = display.newImageRect( sceneGroup, "images/BGgameTable.png", 2048, 2048 ) back.x = centerX back.y = centerY --if(w\>h) then back.rotation = 90 end -- Create a button local push1 = PushButton( sceneGroup, centerX + 400, centerY + 350, "Menu", onBack, { labelColor = {0.8,0.2,0.2}, labelSize = 18 } ) end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:willEnter( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:didEnter( event ) local sceneGroup = self.view Runtime:addEventListener( "enterFrame", tick ) end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:willExit( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:didExit( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- ---------------------------------------------------------------------- function scene:destroy( event ) local sceneGroup = self.view end ---------------------------------------------------------------------- -- FUNCTION/CALLBACK DEFINITIONS -- ---------------------------------------------------------------------- onBack = function ( self, event ) local options = { effect = "fromTop", -- See list here: http://docs.coronalabs.com/daily/api/library/composer/gotoScene.html time = 500, params = { arg1 = "value", arg2 = 0 } } composer.gotoScene( "ifc.mainMenu", options ) return true end --------------------------------------------------------------------------------- -- Scene Dispatch Events, Etc. - Generally Do Not Touch Below This Line --------------------------------------------------------------------------------- function scene:show( event ) sceneGroup = self.view local willDid = event.phase if( willDid == "will" ) then self:willEnter( event ) elseif( willDid == "did" ) then self:didEnter( event ) end end function scene:hide( event ) sceneGroup = self.view local willDid = event.phase if( willDid == "will" ) then self:willExit( event ) elseif( willDid == "did" ) then self:didExit( event ) end end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene 

 I really do not like asking these questions, I feel as though I should know more than I do.

I bet you can “blaze-read” through the above code like an action novel!

:slight_smile:

Thanks, Caleb.

In this case, using a plain localized variable would be better than returning it from a function.

When you localize an object (like “local bankText”), you set it to something by assigning it without local.

So:

local bankText -- Yada, Yada, Yada... bankText = ... -- Set it to display.newText(...) however you do that

Also, if you’re using bankText to display a score or similar, you should just create it once, then, when tick() is called, update its text instead of re-creating it.

  • Caleb