Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

missing text?
Started by milestudios73 Oct 24 2019 05:28 AM

2 replies to this topic

Best Answer Rob Miracle , 24 October 2019 - 03:07 PM

First, the text in "myText" in the tutorial isn't a real language. It's latin like and computer generated to approximate normal human writing. See: https://www.lipsum.com/

 

You found a very subtile bug in the tutorial. The cause of it is your last paragraph doesn't end with a newline.

 

If you take:

or one who avoids a pain that produces no resultant pleasure?]]

and change it to:

or one who avoids a pain that produces no resultant pleasure?
]]

It will work.  The other solution to handle not having a newline at the end of the last paragraph is to change the code like this:
 

repeat
    paragraph, tmpString = string.match( tmpString, "([^\n]*)\n(.*)" )
    if paragraph == nil then 
    	break
    end

Rob

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

milestudios73

[GLOBAL: userInfoPane.html]
milestudios73
  • Observer

  • 9 posts
  • Corona SDK

ok so i followed this tut https://docs.coronalabs.com/tutorial/system/textBlocks/index.html and decided to change the text from the languge its in (dont know it) to english but i keep getting this error

 

15:26:23.276  
15:26:23.276  Copyright (C) 2009-2019  C o r o n a   L a b s   I n c .
15:26:23.276  	Version: 3.0.0
15:26:23.276  	Build: 2019.3541
15:26:23.287  Platform: KFJWI / x64 / 10.0 / Intel(R) HD Graphics 4000 / 4.0.0 - Build 10.18.10.4425 / 2019.3541 / en_US | US | en_US | en
15:26:23.287  Loading project from:   C:\Users\Happy Ezra Miles\Documents\Corona Projects\zvirungamutauro
15:26:23.287  Project sandbox folder: C:\Users\Happy Ezra Miles\AppData\Local\Corona Labs\Corona Simulator\Sandbox\zvirungamutauro-92707F50DCA98CF44E2932EE489E4204\Documents
15:26:23.309  ERROR: Runtime error
15:26:23.309  C:\Users\Happy Ezra Miles\Documents\Corona Projects\zvirungamutauro\sc.lua:36: ERROR: display.newText() missing 'text' parameter (expected string but got nil)
15:26:23.309  stack traceback:
15:26:23.309  	[C]: in function 'error'
15:26:23.309  	?: in function 'gotoScene'
15:26:23.309  	C:\Users\Happy Ezra Miles\Documents\Corona Projects\zvirungamutauro\main.lua:12: in main chunk

and this is my code


local composer = require( "composer" )

local scene = composer.newScene()

-- -----------------------------------------------------------------------------------
-- Code outside of the scene event functions below will only be executed ONCE unless
-- the scene is removed entirely (not recycled) via "composer.removeScene()"
-- -----------------------------------------------------------------------------------
local myText = [[But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. 

No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. 

To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?]]

local widget = require( "widget" )
 
local scrollView = widget.newScrollView(
{
    top = 0,
    left = 0,
    width = display.contentWidth,
    height = display.contentHeight,
    horizontalScrollDisabled = true
})
 
local paragraphs = {}
local paragraph
local tmpString = myText
 
local yStart = 10
local mainPadding = 20

repeat
    paragraph, tmpString = string.match( tmpString, "([^\n]*)\n(.*)" )
    paragraphs[#paragraphs+1] = display.newText( { text=paragraph, width=scrollView.width-(mainPadding*2), fontSize=60 } )
    paragraphs[#paragraphs].anchorX = 0
    paragraphs[#paragraphs].anchorY = 0
    paragraphs[#paragraphs].x = mainPadding
    paragraphs[#paragraphs].y = yStart
    paragraphs[#paragraphs]:setFillColor( 0 )
    scrollView:insert( paragraphs[#paragraphs] )
    yStart = yStart + paragraphs[#paragraphs].height
until tmpString == nil or string.len( tmpString ) == 0

scrollView:setScrollHeight( scrollView:getView().height + (mainPadding*2) )




-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------

-- create()
function scene:create( event )

	local sceneGroup = self.view
	-- Code here runs when the scene is first created but has not yet appeared on screen

end


-- show()
function scene:show( event )

	local sceneGroup = self.view
	local phase = event.phase

	if ( phase == "will" ) then
		-- Code here runs when the scene is still off screen (but is about to come on screen)

	elseif ( phase == "did" ) then
		-- Code here runs when the scene is entirely on screen

	end
end


-- hide()
function scene:hide( event )

	local sceneGroup = self.view
	local phase = event.phase

	if ( phase == "will" ) then
		-- Code here runs when the scene is on screen (but is about to go off screen)

	elseif ( phase == "did" ) then
		-- Code here runs immediately after the scene goes entirely off screen

	end
end


-- destroy()
function scene:destroy( event )

	local sceneGroup = self.view
	-- Code here runs prior to the removal of scene's view

end


-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -----------------------------------------------------------------------------------

return scene

please help my assignment is due next week Wednesday  :(

 



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,300 posts
  • Enterprise

  Best Answer

First, the text in "myText" in the tutorial isn't a real language. It's latin like and computer generated to approximate normal human writing. See: https://www.lipsum.com/

 

You found a very subtile bug in the tutorial. The cause of it is your last paragraph doesn't end with a newline.

 

If you take:

or one who avoids a pain that produces no resultant pleasure?]]

and change it to:

or one who avoids a pain that produces no resultant pleasure?
]]

It will work.  The other solution to handle not having a newline at the end of the last paragraph is to change the code like this:
 

repeat
    paragraph, tmpString = string.match( tmpString, "([^\n]*)\n(.*)" )
    if paragraph == nil then 
    	break
    end

Rob



[TOPIC: post.html]
#3

milestudios73

[GLOBAL: userInfoPane.html]
milestudios73
  • Observer

  • 9 posts
  • Corona SDK

thank you sir




[topic_controls]
[/topic_controls]