problem pausing

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Tied_Effect
Prole
Posts: 2
Joined: Mon Sep 27, 2021 5:23 am

problem pausing

Post 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

--------
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

Re: problem pausing

Post 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.
obey
Tied_Effect
Prole
Posts: 2
Joined: Mon Sep 27, 2021 5:23 am

Re: problem pausing

Post 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
User avatar
Gunroar:Cannon()
Party member
Posts: 1141
Joined: Thu Dec 10, 2020 1:57 am

Re: problem pausing

Post 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
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests