(Solved) Disabling the inventory on a menu screen with VerbCoin template

Started by Jabbage, Sun 02/10/2022 19:35:18

Previous topic - Next topic

Jabbage

Hi all! This is my first time asking a question here, so I'm really hoping it's not TOO dumb!  :-D

My game has a beginning room which is a menu screen. I'm using the VerbCoin template, so the inventory appears when the users right clicks. I have also created a custom GUI which contains save, return, quit buttons which appears when the user presses Escape.

I've been trying to find ways to disable the inventory screen and my custom GUI on the title so that this kind of thing doesn't happen!



I found this advice from 2017 but it was for a menu which appears when the user hovers their mouse near the top of the screen.

Any advice is really appreciated, thanks!



Khris

Add this to your room_script:

Code: ags
function on_key_press(eKeyCode key) {
  ClaimEvent();
}

function on_mouse_click(MouseButton button) {
  ClaimEvent();
}

This will disable any mouse/keyboard code from other scripts in that room.

Jabbage

Thank you, this works brilliantly for the menu screen!

Unfortunately I've realised there's another instance in the game where I'd like to be able to disable the inventory and my save/load menu, but I've set it up so that the user is supposed to be able to use the keyboard and mouse.

When the player starts the game, I've made a few screens featuring introductory text and images - basically like a slide show, briefly introducing the characters and world. I wanted to make sure the player could take their time to read these or skip them if they want to get straight into playing the game, so I set it so they could click to continue, or press a keyboard button to skip.

Code: ags
function on_mouse_click (MouseButton)
{
player.ChangeRoom(302);
}

function on_key_press (eKeyCode)
{
player.ChangeRoom(1);
}

(Room 302 is the next 'slide' in the intro, room 1 is the true beginning of the game)

So, if I 'Claim event' on both keyboard and mouse, this will stop working! I had a try at putting something together which might allow me to disable the escape button and right click, but it doesn't work...


Code: ags
function on_mouse_click(MouseButton button)
{
  if (button == eMouseRight)
	{ ClaimEvent();}
  else
  player.ChangeRoom(303);
}

function on_key_press(eKeyCode key)   
  {
  if(eKeyEscape) 
  ClaimEvent();
  else 
  player.ChangeRoom(1, 150, 150, eDirectionDown);
  }

It's possible I should have a rethink and handle this introductory text in a different way?

Khris

Just add the ClaimEvent(); command to your functions. What it does is tell AGS not to run any other script's handler, so there's no need to put it in a conditional. For the key you'd use if (key == eKeyEscape) btw.

Code: ags
function on_mouse_click(MouseButton button)
{
  ClaimEvent();
  player.ChangeRoom(302);
}

function on_key_press(eKeyCode key)
{
  ClaimEvent();
  player.ChangeRoom(1);
}

edit: fixed typos

Jabbage

Brilliant, thank you! I think I understand better now ClaimEvent works now.

I'll mark this thread as solved!

SMF spam blocked by CleanTalk