How do I simulate the esc menu? (Pausing everything)

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

How do I simulate the esc menu? (Pausing everything)

Post by sheamkennedy »

I am working on a slice based menu for my game. I would like the game to essentially pause just like what happens when you normally click "esc" during gameplay. My current menu script uses suspend player and NPC but this doesn't work for my slices (like weapon animations) which continue to proceed in the background once the menus up. Is there a simple way to solve this or is using a slice based menu going to be a challenge?

I also want this menu to allow the player to switch through their weapon an item inventory by using the up, down, left and right buttons and display the corresponding weapon/item slices as the player flips through them. I fear that this could make things even harder since specified slices shouldn't pause while others should...

Hope someone can clear this up.

If worse comes to worse I don't think it would be a bad thing to have my menu not pause the game whatsoever but instead just suspend the hero... we'll see, might do that instead.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
kylekrack
Liquid Metal Slime
Posts: 1242
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Post by kylekrack »

To make the slices pause is pretty easy, although you may have to go into your scripts and rework it to make everything work, depending on how complicated your scripts are. The easiest way to make everything pause in the slice world (or the way I've found it easiest) is to basically have a global variable that you check every time a script is used which moves a slice.

For example, this variable may be called "paused," and you call

Code: Select all

if(not(paused)) then(
     # do slice moving here
)
And you make paused true when you open the menu. Or you could do the opposite and have a variable like "game is playing" which you set to false when the menu opens. You can get more complicated with the globals depending on how complicated your scripts are.

As for inventories displaying pictures, you'd have to create an entirely custom inventory to do this, at this point. There is no implemented feature of which I am aware that allows you to customize the item menu. I'll be honest and tell you that in my opinion, it's simply not worth it to script a custom menu, unless it's really simple. I would rather just wait until there's a little bit more customizability of what's already there.

However, I can tell you that it is definitely possible with a slice collection and "selected menu item(menu item true slot())". Good luck on your travels, and I'm sorry I don't have more help to offer, but I'd be willing to help you figure something out if you need help, although I'm certain there are others who could help you more quickly and effectively.[/code]
My pronouns are they/them
Ps. I love my wife
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Hmm I see what you mean. I think this would get difficult with my code. I have over 6000 lines of code (some is garbage need to go through) and so many scripts and stuff to handle. I think what you are suggesting may be unfeasible.

It's actually not a big deal. I got the menu to look nice while everything in the background remains in motion. Mind you I do have to build the inventory and script key-press to scroll through it. My games inventory will be relatively small since it's a zelda-like style so I'm not going to have armour, clothes and a lot of the other things that could build up a huge inventory in an RPG.

Right now I'm actually just having trouble making a timer which checks when if the menu was just opened or just closed. I want an adequate time in between when the menu can open and can close because currently when I click the menu button it opens and closes rapidly each tick, so I'd rather increase the lag time between presses. I think I'll figure this out tomorrow, I'm so tired my screens getting wavy so maybe my thought process is not at it's best right now.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
kylekrack
Liquid Metal Slime
Posts: 1242
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Post by kylekrack »

Ah, that makes the inventory a lot easier to manage. And yeah, that timer thing shouldn't be too tough. I think there's actually an even simpler way of giving some lag time on the menu opening and closing. I think I have it in one of my scripts somewhere. TMC helped me out with that so I can't remember it off the top of my head. But yeah, if you're struggling with that, it's probably good to get some sleep.
My pronouns are they/them
Ps. I love my wife
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

kylekrack wrote:Ah, that makes the inventory a lot easier to manage. And yeah, that timer thing shouldn't be too tough. I think there's actually an even simpler way of giving some lag time on the menu opening and closing. I think I have it in one of my scripts somewhere. TMC helped me out with that so I can't remember it off the top of my head. But yeah, if you're struggling with that, it's probably good to get some sleep.
Hey that sounds like a really useful script. Mind sharing that lag thing when you come across it. No rush, I won't be checking back until tomorrow evening probably anyways. Off to bed now.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
kylekrack
Liquid Metal Slime
Posts: 1242
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Post by kylekrack »

Code: Select all

if(keyval(key:esc) > 1 || keyval(key:filtered alt) > 1) then(
		open menu(0)
	)
Here's the script I was talking about. I think basically this prevents it from being triggered repeatedly as a result of a key being held down. Something like that. Maybe TMC can help explain, or I could go back and look for his explanation.
My pronouns are they/them
Ps. I love my wife
User avatar
Gizmog
Metal King Slime
Posts: 2622
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

I have a feeling there's not going to be a good answer to this. The main menu acts the way it does because of the Menu Bitset "Allow Gameplay and Scripts?". In theory, you could set up a custom menu to block stuff moving around, except like you say, then you'd be unable to control the bits of it you want to control.

If you were a crazy person, you could set up a tangled web of While Loops to iterate through every slice there is, every sibling of every child of every child, record what handle the slice is and how fast it was going to a new slice in a container somewhere, and stash 'em away till it was time for them to move again. Then, you'd have another while loop go through that container and set whatever handle's speed to whatever speed we wrote down.

If you were slightly less crazy, you could organize the slices you know are going to be problematic (enemy shots, weapon animations, etc) into their own containers and merely iterate through those turning their speed on and off.

Just to clarify what I mean about writing down the values:

Code: Select all

script,FreezeSlice,WhatSlice,begin
variable (UnfreezeTicket)
UnfreezeTicket := createcontainer
SetSliceExtra (UnfreezeTicket,0,GetSliceVelocityX (WhatSlice))
SetSliceExtra (UnfreezeTicket,1,GetSliceVelocityY (WhatSlice))
SetSliceExtra (UnfreezeTicket,2,WhatSlice)
StopSlice (WhatSlice)
SetParent (UnfreezeTicket,UnfreezeQueue)
end

script,UnfreezeLoop,begin
variable (Unfreezing)
Unfreezing := FirstChild (UnfreezeQueue)
while (Unfreezing)
do (
 UnfreezeSlice (Unfreezing)
 Unfreezing := NextSibling (Unfreezing)
 )
end

script,UnfreezeSlice,WhatSlice,begin
variable (NewVelX,NewVelY,WhoseNewVel)
NewVelX := GetSliceExtra (0,WhatSlice)
NewVelY := GetSliceExtra (1,WhatSlice)
WhoseNewVel := GetSliceExtra (2,WhatSlice)
SetSliceVelocity (WhoseNewVel,NewVelX,NewVelY)
end
No idea if that'd even compile, just.. that's the idea. Even then, there's a million problems with it: Slices you'd told to move to a certain X/Y are no longer going to remember where they were supposed to stop. Problems like this are part of the reason my Clown Game is taking me longer than I thought it would, 'cause what seem like simple design goals ("There should be a pause button that plays cool pause music") turn out to be a terrible mess.

I've got a million more BAD solutions to this problem (Every slice has its X/Y velocity recorded in extra data or containers, and every tick of "gameplay" it moves that many pixels in those directions for just one tick being maybe the best of the worst, with the menu switching out of gameplay to "menu" so nobody moves or checks collisions until you're back in "gameplay".) but nothing that seems like it's very practical. I can't wait to see what TMC suggests.
User avatar
Gizmog
Metal King Slime
Posts: 2622
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

kylekrack wrote:

Code: Select all

if(keyval(key:esc) > 1 || keyval(key:filtered alt) > 1) then(
		open menu(0)
	)
Here's the script I was talking about. I think basically this prevents it from being triggered repeatedly as a result of a key being held down. Something like that. Maybe TMC can help explain, or I could go back and look for his explanation.
That script utilizes the keyval command to check the KeyPress situation more specifically than KeyIsPressed. As the dictionary explains, KeyVal returns 0 if the key isn't being pressed at all, 1 if the key is still being held down since the last tick, 2 if the player pressed and released in the same tick and 3 if the player has newly pressed the key in that tick or typematic (the glorious "aaaaaaaaaaaaaaaaa" that pops up when you hold down a key) has triggered a new key-press. When he says > 1, he's meaning situation 2 or 3.

the reason you'd do this over KeyIsPressed is because if you check "KeyIsPressed" every tick, it's going to tell you it's true every tick, and thus trigger 18.2 times a second. KeyVal > 1 is going to tell you it's true about the same as you'd expect for typing. He's also being really smart and checking both Escape AND the Alt Keys, because the OHR Default for menus is either of 'em and you have no way of knowing what a particular player is used to. He's also being triply smart and using the Filtered Alt thing which I didn't even know about, but apparently double checks and makes sure the player isn't doing an Alt-Tab or an Alt-Space or Alt-Whatever kind of command first.[/url]
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

I actually created a command to suspend slice movements, but never finished and added it to the OHR source. (I think this was in the middle of the last Random Collab contest, so I just dropped it when I discovered I didn't need it afterall.) I definitely should dig that up. I think the plan was to split it up into two separate commands to suspend slice movement, and suspend hero and NPC movement (or even three commands). In other words, the ability to separately pause NPCs in mid-step. A command to suspend NPC activation globally would be nice too. Are there any other suspend commands missing?

Oh, I think another reason I delayed adding that command is because I though it would be more useful to be able to pause a slice and all its descendants, in the same way you can mark a slice and its descendants invisible. Then suspend/resume slice movement would just mark the root slice as paused.
sheamkennedy wrote:Hmm I see what you mean. I think this would get difficult with my code. I have over 6000 lines of code (some is garbage need to go through) and so many scripts and stuff to handle.
There is the "suspend timers" command, which you can use to help prevent other scripts from running, other than on-keypress scripts and other triggered stuff. However, aside from that I don't have a better option.

And that key:filteredalt thing is just as Giz described; it waits for key-up of the alt key to ensure no kind of window manager key combination is being used. It's a gotcha and a case of back-compat breakage that the engine actually uses filteredalt instead of alt everywhere. But it didn't used to be that way, so older games which just checked alt when trying to prevent the main menu from triggering may now break. Maybe a back-compat bitset should be added to revert to the old behaviour.
Last edited by TMC on Wed Mar 11, 2015 12:21 pm, edited 2 times in total.
Post Reply