Page 1 of 1

problem pausing

Posted: Mon Sep 27, 2021 5:51 am
by Tied_Effect
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

--------

Re: problem pausing

Posted: Mon Sep 27, 2021 3:05 pm
by BrotSagtMist
Very complicated, I usually pause by simply renaming the update.
So i do
Running=love.update
love.update=function(dt) blah end --pause screen logic
to enter pause and to leave it just reverse
love.update=Running

The draw function will just show a static picture in this case, either replace that too or draw your pause message on top.

Re: problem pausing

Posted: Wed Sep 29, 2021 5:53 am
by Tied_Effect
I'm kind of confused as to what's suppose to go inside "blah".
Here's what I put inside it

PauseState1 = Class{__includes = BaseState}

function PauseState1:enter(enterParams)
Running = love.update
love.update = function(dt)
backgroundScroll = (backgroundScroll + BACKGROUND_SCROLL_SPEED * dt) % BACKGROUND_LOOPING_POINT
groundScroll = (groundScroll + GROUND_SCROLL_SPEED * dt) % VIRTUAL_WIDTH
end
end

function PauseState1:exit(enterParams)
love.update = Running
love.update = function(dt)
end
end

Re: problem pausing

Posted: Thu Sep 30, 2021 5:38 pm
by Gunroar:Cannon()
It seems PauseState1:enter is called in the state machine without any parameters.
And isn't PauseState1 a state that takes over the game, which takes over love.update with its own update function if you put PauseState1:update? But I get that's optional, though thats how hump/gamestates.lua is if registerEvents is used :P