Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Rik_Vargard on Sat 05/02/2022 13:15:59

Title: [SOLVED] How to disable gPanel GUI in one particular room
Post by: Rik_Vargard on Sat 05/02/2022 13:15:59
Hello!

All right I'm out of options and tries:

All I want is to not be able to either click the ESC key to have the gPanel GUI appear in a room (main title screen room).

I tried to disable the ESC key in that room, or to disable the gPanel GUI so when pressing ESC nothing would happen.

The closest I got was making the Visible to false in repExec but of course it won't work because it shows up for like a millisecond then is invisible again

I feel it's just out there but I can't find the solution.
Title: Re: How to disable ESC key or gPanel GUI in one particular room
Post by: Crimson Wizard on Sat 05/02/2022 13:38:10
Quote from: Rik_Vargard on Sat 05/02/2022 13:15:59
I tried to disable the ESC key in that room, or to disable the gPanel GUI so when pressing ESC nothing would happen.

Please explain in detail what did you do?
Title: Re: How to disable ESC key or gPanel GUI in one particular room
Post by: Rik_Vargard on Sat 05/02/2022 14:25:14
Hi, thanks for the reply!

Well I tried lot :P
The idea is that the player wouldn't be able to open gPanel by pressing the ESC key in my first room (with "new" - "load" - "quit")

Some things I tried that i remember are:

gPanel.Visible = false;

GuiOff(3); (old?)

gPanel.Transparency = 100;

or like :
(example)
Code (ags) Select

if(keycode ==eKeyEscape)
{
// diffrent tries like
gPanel.Transparency = 100;
//or
gPanel.Visible = false;
}




The thing I want to avoid is this :

Spoiler

(https://i.ibb.co/C115T1s/problem.jpg)
[close]

Title: Re: How to disable ESC key or gPanel GUI in one particular room
Post by: eri0o on Sat 05/02/2022 14:28:19
The esc key is probably something that's in your global script, isn't it?

Also your images aren't loading for me.
Title: Re: How to disable ESC key or gPanel GUI in one particular room
Post by: Crimson Wizard on Sat 05/02/2022 14:33:06
Quote from: Rik_Vargard on Sat 05/02/2022 14:25:14
The idea is that the player wouldn't be able to open gPanel by pressing the ESC key in my first room (with "new" - "load" - "quit")

Well, you have a command somewhere that performs that action by ESC key press. You need to find it in your script, and add a condition that player.Room is not certain room.

Title: Re: How to disable ESC key or gPanel GUI in one particular room
Post by: Rik_Vargard on Sat 05/02/2022 14:54:45
Is this working for the image?
Spoiler
(http://i.ibb.co/C115T1s/problem.jpg)
[close]
or
Spoiler
https://i.ibb.co/C115T1s/problem.jpg (https://i.ibb.co/C115T1s/problem.jpg)
[close]

And yes I found this in globalcript in game_start :

initialize_control_panel();

But I don't know how to use it in a room if it's even possible

I also tried close_gui(gPanel); on room load

Quote from: Crimson Wizard on Sat 05/02/2022 14:33:06
Well, you have a command somewhere that performs that action by ESC key press. You need to find it in your script, and add a condition that player.Room is not certain room.

Yes I've been looking for that too

I tried

Code (ags) Select

if (keycode == eKeyEscape)
  {
   close_gui(gPanel);
  }


But keycode is undefined symbol error
Title: Re: How to disable ESC key or gPanel GUI in one particular room
Post by: Crimson Wizard on Sat 05/02/2022 14:55:38
Quote from: Rik_Vargard on Sat 05/02/2022 14:54:45
I tried

Code (ags) Select

if (keycode == eKeyEscape)
  {
   close_gui(gPanel);
  }



Your approach is wrong. You want to prevent certain action from happening, and trying to solve that by making a second action countering the first.
Instead you should find a way to not do the first action at all. You need to find where the panel is opened with Escape key, and add a condition there.



To elaborate a little more, suppose you have something like this in GlobalScript somewhere:
Code (ags) Select

function on_key_press(eKeyCode keycode)
{
    if (keycode == eKeyEscape)
    {
         open_gui(gPanel);
    }
}


Then you may change this to:
Code (ags) Select

function on_key_press(eKeyCode keycode)
{
    if (keycode == eKeyEscape)
    {
         if (player.Room != 1) // don't do if the room is 1
         {
              open_gui(gPanel);
         }
    }
}


Alternatively, if you do not want to use room numbers, you may set up Custom Properties (https://adventuregamestudio.github.io/ags-manual/CustomProperties.html) for your rooms, and make a property that tells if gPanel is allowed or not, and check that instead.
Title: Re: How to disable ESC key or gPanel GUI in one particular room
Post by: Rik_Vargard on Sat 05/02/2022 19:28:33
Okkk  ok ok... phew... I finally got it.

I went to add your first part of the code in the global script, and found out it's already there, with all other keycode stuff.
Good thing I backed up the game because I messed it up while trying, especially since I needed the same thing for other rooms.

So in fact it all happens in the global script and not the rooms (like eri0o mentioned before, in fact - thanks for that!) . Or perhaps with custom properties ( thanks for the link) which is a whole new world to me, for another day! Baby steps eh... :P

Now I have this :

Code (ags) Select

function on_key_press(eKeyCode keycode)
{
    if (keycode == eKeyEscape)
    {
// all other if stuff
        else if (player.Room == 1 || player.Room == 9 || player.Room == 2)
         {
          close_gui(gPanel);
         }
        else open_gui(gPanel);
    }
}


Thanks to this I now learned != , || , && and mostly how to use Keycode .  8-0

Well, thank you SO much for everything!!
Title: Re: [SOLVED] How to disable gPanel GUI in one particular room
Post by: Khris on Mon 07/02/2022 13:42:05
You can do this instead:
Code (ags) Select
function on_key_press(eKeyCode keycode)
{
    if (keycode == eKeyEscape) {
      if (player.Room >= 3 && player.Room != 9) open_gui(gPanel);
      else close_gui(gPanel);
    }
}


edit: I thought calling close_gui isn't required but realized it absolutely is, so this alternate way is kind of pointless. Feel free to ignore this post  :-D
Title: Re: [SOLVED] How to disable gPanel GUI in one particular room
Post by: Rik_Vargard on Mon 07/02/2022 20:09:24
 :-D :-D :-D

Well I do have to thank you for taking the time to think about it && to reply!

I'm laughing but I'm also serious about it.

Cheers and Thanks!!