Next line not displaying on click
Posted: Tue Apr 18, 2023 1:21 am
this is my code, I am trying to program it so that it goes to next line on click (or display remaning characters if the line has more characters to print, but it is not doing so and I am not sure why it isn't.
Code: Select all
local dialoguePage = {}
local currentScreen = startScreen
local requestPage = require("requestPage")
textToDisplay = {
"line1",
"line2",
"line3",
"line4"
}
currentLine = 1
numberOfCharsToDisplay = 0
timePassed = 0
timeForEachChar = 0.25
function dialoguePage.load()
end
function dialoguePage.update(dt)
timePassed = timePassed + dt
if timePassed >= timeForEachChar then
timePassed = timePassed - timeForEachChar
numberOfCharsToDisplay = numberOfCharsToDisplay + 1
end
love.mousepressed(x, y, button)
end
function dialoguePage.draw()
love.graphics.print(textToDisplay[currentLine]:sub(1, numberOfCharsToDisplay), 0, 0)
end
function dialoguePage.mousepressed(x, y, button)
if button == 1 then
if numberOfCharsToDisplay >= #textToDisplay[currentLine] then
-- Move to the next line of text
currentLine = currentLine + 1
if currentLine > #textToDisplay then
-- If we've reached the end of the text, move to the next screen
currentScreen = requestPage
else
-- Otherwise, reset the number of characters to display
numberOfCharsToDisplay = 0
end
else
-- If the current line is not fully displayed, show the full line and move to the next line
numberOfCharsToDisplay = #textToDisplay[currentLine]
currentLine = currentLine + 1
if currentLine > #textToDisplay then
-- If we've reached the end of the text, move to the next screen
currentScreen = requestPage
end
end
end
end
return dialoguePage