problem pausing
Posted: Mon Sep 27, 2021 5:51 am
I've been trying to get the pause feature to work for over a month now.
In my latest attempt, I tried using this one.
Now I'm getting
--------
Error
states/PauseState.lua:40: attempt to index local 'enterParams' (a nil value)
Traceback
states/PauseState.lua:40: in function 'enter'
StateMachine.lua:55: in function 'change'
main.lua:145: in function <main.lua:137>
[C]: in function 'xpcall'
--------
This is the code I have, could someone please help?
--------
--PauseState = Class{__includes = BaseState}
--paase = 1
--scoreSaver = score
--savedTimer = timer
--OLD_GROUND_SCROLL_SPEED = GROUND_SCROLL_SPEED
--GROUND_SCROLL_SPEED = 0
--OLD_BACKGROUND_SCROLL_SPEED = BACKGROUND_SCROLL_SPEED
--BACKGROUND_SCROLL_SPEED = 0
PauseState = Class{__includes = BaseState}
function PauseState:init()
self.timer = 0
self.enterParams = {}
end
function PauseState:update(dt)
self.timer = self.timer + dt
if love.keyboard.wasPressed('enter') or love.keyboard.wasPressed('return') then
self.enterParams = {
['bird'] = self.bird,
['pipePairs'] = self.pipePairs,
['timer'] = self.timer,
['score'] = self.score
}
self.timer = self.timer + dt * 1
gStateMachine:change('play', self.enterParams)
end
end
function PauseState:enter(enterParams)
scrolling = false
self.bird = enterParams.bird
self.pipePairs = enterParams.pipePairs
self.timer = enterParams.timer
self.score = enterParams.score
end
function PauseState:render()
love.graphics.setFont(flappyFont)
love.graphics.printf('The game paused!', 0, 64, VIRTUAL_WIDTH, 'center')
love.graphics.setFont(mediumFont)
love.graphics.printf('Press Enter to continue', 0, 100, VIRTUAL_WIDTH, 'center')
love.graphics.print(self.timer .. tostring(self.score), 8, 38)
end
--------
In my latest attempt, I tried using this one.
Now I'm getting
--------
Error
states/PauseState.lua:40: attempt to index local 'enterParams' (a nil value)
Traceback
states/PauseState.lua:40: in function 'enter'
StateMachine.lua:55: in function 'change'
main.lua:145: in function <main.lua:137>
[C]: in function 'xpcall'
--------
This is the code I have, could someone please help?
--------
--PauseState = Class{__includes = BaseState}
--paase = 1
--scoreSaver = score
--savedTimer = timer
--OLD_GROUND_SCROLL_SPEED = GROUND_SCROLL_SPEED
--GROUND_SCROLL_SPEED = 0
--OLD_BACKGROUND_SCROLL_SPEED = BACKGROUND_SCROLL_SPEED
--BACKGROUND_SCROLL_SPEED = 0
PauseState = Class{__includes = BaseState}
function PauseState:init()
self.timer = 0
self.enterParams = {}
end
function PauseState:update(dt)
self.timer = self.timer + dt
if love.keyboard.wasPressed('enter') or love.keyboard.wasPressed('return') then
self.enterParams = {
['bird'] = self.bird,
['pipePairs'] = self.pipePairs,
['timer'] = self.timer,
['score'] = self.score
}
self.timer = self.timer + dt * 1
gStateMachine:change('play', self.enterParams)
end
end
function PauseState:enter(enterParams)
scrolling = false
self.bird = enterParams.bird
self.pipePairs = enterParams.pipePairs
self.timer = enterParams.timer
self.score = enterParams.score
end
function PauseState:render()
love.graphics.setFont(flappyFont)
love.graphics.printf('The game paused!', 0, 64, VIRTUAL_WIDTH, 'center')
love.graphics.setFont(mediumFont)
love.graphics.printf('Press Enter to continue', 0, 100, VIRTUAL_WIDTH, 'center')
love.graphics.print(self.timer .. tostring(self.score), 8, 38)
end
--------