How to overwrite pause screen?

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
AlanLive2020
Dolphin
Dolphin
Posts: 89
Joined: Fri Nov 27, 2020 8:15 am
Pronouns: he/him

How to overwrite pause screen?

Postby AlanLive2020 » Sun Jul 03, 2022 8:44 pm

Hi. I'm just experimenting a few things for entertainment and I wanted to know if it's possible to replace the pause screen or disable it to add a custom menu.

This is less important, but it is also possible to restart the stage without waiting for the death animation to end?

deice
Ripper II
Ripper II
Posts: 327
Joined: Fri Jul 23, 2021 7:35 am

Re: How to overwrite pause screen?

Postby deice » Mon Jul 04, 2022 8:31 am

AlanLive2020 wrote:
Sun Jul 03, 2022 8:44 pm
Hi. I'm just experimenting a few things for entertainment and I wanted to know if it's possible to replace the pause screen or disable it to add a custom menu.
yes. the simplest way to do it is to check whether the game has been paused outside of a lua script (Misc.isPaused(), Misc.isPausedByLua()) and then unpause it before pausing it yourself and then handling the menu logic in a lua script.
if you want a simple example, there's this script.
AlanLive2020 wrote:
Sun Jul 03, 2022 8:44 pm
This is less important, but it is also possible to restart the stage without waiting for the death animation to end?
yes, but the complexity depends on what exactly you mean by that. you can just instantly reload the entire level as soon as the player dies which isn't very hard to do. however, if you don't want the little loading screen to happen every single time, you need something more complex like rooms. however, this script has an absolute myriad of tiny issues and bugs that sneak in as a consequence of using it, so i don't recommend it unless you know how to account for those edge cases and fix them in your own code.

AlanLive2020
Dolphin
Dolphin
Posts: 89
Joined: Fri Nov 27, 2020 8:15 am
Pronouns: he/him

Re: How to overwrite pause screen?

Postby AlanLive2020 » Mon Jul 04, 2022 2:36 pm

deice wrote:
Mon Jul 04, 2022 8:31 am
AlanLive2020 wrote:
Sun Jul 03, 2022 8:44 pm
Hi. I'm just experimenting a few things for entertainment and I wanted to know if it's possible to replace the pause screen or disable it to add a custom menu.
yes. the simplest way to do it is to check whether the game has been paused outside of a lua script (Misc.isPaused(), Misc.isPausedByLua()) and then unpause it before pausing it yourself and then handling the menu logic in a lua script.
if you want a simple example, there's this script.
AlanLive2020 wrote:
Sun Jul 03, 2022 8:44 pm
This is less important, but it is also possible to restart the stage without waiting for the death animation to end?
yes, but the complexity depends on what exactly you mean by that. you can just instantly reload the entire level as soon as the player dies which isn't very hard to do. however, if you don't want the little loading screen to happen every single time, you need something more complex like rooms. however, this script has an absolute myriad of tiny issues and bugs that sneak in as a consequence of using it, so i don't recommend it unless you know how to account for those edge cases and fix them in your own code.
Thank you. I'll take note of that.

Btw i mean like a way to press a button to skip the death animation for less waiting on each death.

AlanLive2020
Dolphin
Dolphin
Posts: 89
Joined: Fri Nov 27, 2020 8:15 am
Pronouns: he/him

Re: How to overwrite pause screen?

Postby AlanLive2020 » Tue Jul 05, 2022 6:05 pm

So apparently the pause function via lua just softlocks the game for some reason, it won't read any inputs

I tried to do this:

Code: Select all

if player.rawKeys.pause and pause == true then
    pause = false
end
if menuOpen == true then
    Misc.pause(false)
    if menuOpen == true and player.rawKeys.pause and pause == true then
        menuOpen = false
    end
end
if menuOpen == false then
    Misc.unpause()
end
end
function onDraw()
if menuOpen == true then
    Graphics.drawScreen{color = Color.black.. 0.75,priority = 0}
end
end
function onPause(evt)
menuOpen = true
Misc.pause(false)
pause = true
evt.cancelled = true;
end
The pause variable is used so that the menu won't open and close every frame while the button is held

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9382
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: How to overwrite pause screen?

Postby Enjl » Tue Jul 05, 2022 9:29 pm

What function is this in? Functions like onTick and onTickEnd don't run while paused by design.

Here is what I usually do:

Code: Select all

local isPaused = false

function onPause(e)
	e.cancelled = true -- cancel default measures of pausing
end

function onInputUpdate()
	if player.keys.paused == KEYS_PRESSED then
		if isPaused then
			Misc.unpause()
		else
			Misc.pause()
		end
	end
	if isPaused then
		-- handle input
	end
end

function onDraw()
	if isPaused then
		-- draw pause menu
	end
end

AlanLive2020
Dolphin
Dolphin
Posts: 89
Joined: Fri Nov 27, 2020 8:15 am
Pronouns: he/him

Re: How to overwrite pause screen?

Postby AlanLive2020 » Tue Jul 05, 2022 10:17 pm

Enjl wrote:
Tue Jul 05, 2022 9:29 pm
What function is this in? Functions like onTick and onTickEnd don't run while paused by design.

Here is what I usually do:

Code: Select all

local isPaused = false

function onPause(e)
	e.cancelled = true -- cancel default measures of pausing
end

function onInputUpdate()
	if player.keys.paused == KEYS_PRESSED then
		if isPaused then
			Misc.unpause()
		else
			Misc.pause()
		end
	end
	if isPaused then
		-- handle input
	end
end

function onDraw()
	if isPaused then
		-- draw pause menu
	end
end
Thanks. I tried using onDraw and it also didn't work (maybe i did something wrong). I'm guessing game ticks only run when the game is unpaused. I'm just trying to see if i can make a menu that displays star coins in levels.
Last edited by AlanLive2020 on Tue Jul 05, 2022 10:59 pm, edited 2 times in total.

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9382
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: How to overwrite pause screen?

Postby Enjl » Tue Jul 05, 2022 10:45 pm

AlanLive2020 wrote:
Tue Jul 05, 2022 10:17 pm
Thanks. I tried using onDraw and it also didn't work. I'm guessing game ticks only run when the game is unpaused.
onDraw will work while paused. If it didn't, background objects and sizables would disappear when pausing :p
onTick and onTickEnd specifically don't run while paused, as described in the docs.
https://docs.codehaus.moe/#/reference/l ... ick-events

AlanLive2020
Dolphin
Dolphin
Posts: 89
Joined: Fri Nov 27, 2020 8:15 am
Pronouns: he/him

Re: How to overwrite pause screen?

Postby AlanLive2020 » Wed Jul 06, 2022 10:18 pm

Enjl wrote:
Tue Jul 05, 2022 10:45 pm
AlanLive2020 wrote:
Tue Jul 05, 2022 10:17 pm
Thanks. I tried using onDraw and it also didn't work. I'm guessing game ticks only run when the game is unpaused.
onDraw will work while paused. If it didn't, background objects and sizables would disappear when pausing :p
onTick and onTickEnd specifically don't run while paused, as described in the docs.
https://docs.codehaus.moe/#/reference/l ... ick-events
Still softlocks

Code: Select all

local cooldown = 60 -- goes down by 1 each tick
function onInputUpdate()
	if player.keys.pause == KEYS_PRESSED then
		if isPaused == true and cooldown <= 0 then
			Misc.unpause()
        end
		if isPaused == false and cooldown <= 0 then
        Misc.pause(false)
		end
	end
	if isPaused == true then
		
	end
end

function onDraw()
	if isPaused == true then
        Text.print("Menu", 300, 250)
    Graphics.drawScreen{color = Color.black.. 0.75,priority = 0}
    end
end
function onPause(e)
	e.cancelled = true
end

Hoeloe
Foo
Foo
Posts: 1435
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: How to overwrite pause screen?

Postby Hoeloe » Thu Jul 07, 2022 7:44 am

A few things:

1) There's no reason to specifically detect the pause key being pressed, you can just use the onPause function you're already accessing for that.
2) == true is almost never useful, you can just do if isPaused then, which is the preferred method.
3) You're never actually decrementing your cooldown variable, so it's never less than zero.

This code would work better:

Code: Select all

local cooldown = 60
local isPaused = false

function onInputUpdate()
	if cooldown > 0 then
		cooldown = cooldown -1 
	end
end

function onPause(e)
	e.cancelled = true
	
	if cooldown <= 0 then
		if isPaused then
			Misc.unpause()
		else
			Misc.pause()
		end
		cooldown = 60
	end
end

function onDraw()
	if isPaused then
		Graphics.drawScreen{color = Color.black.. 0.75,priority = 0}
		Text.printWP("Menu", 300, 250, 0)
	end
end

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9382
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: How to overwrite pause screen?

Postby Enjl » Thu Jul 07, 2022 7:58 am

I tend to use onInputUpdate as I have gotten inconsistent results in onPause, though I don't recall the specifics unfortunately. If that indeed works better, then that's good to know.


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest