[SOLVED] How to disable gPanel GUI in one particular room

Started by Rik_Vargard, 05 Feb 2022, 13:15

« previous - next »

Rik_Vargard

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.

Crimson Wizard

Quote from: Rik_Vargard on 05 Feb 2022, 13:15
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?

Rik_Vargard

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

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




The thing I want to avoid is this :

[spoiler]

[/spoiler]


eri0o

The esc key is probably something that's in your global script, isn't it?

Also your images aren't loading for me.

Crimson Wizard

#4
Quote from: Rik_Vargard on 05 Feb 2022, 14:25
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.


Rik_Vargard

Is this working for the image?
[spoiler][/spoiler]
or
[spoiler]https://i.ibb.co/C115T1s/problem.jpg[/spoiler]

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 05 Feb 2022, 14:33
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

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


But keycode is undefined symbol error

Crimson Wizard

#6
Quote from: Rik_Vargard on 05 Feb 2022, 14:54
I tried

Code: ags

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

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


Then you may change this to:
Code: ags

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 for your rooms, and make a property that tells if gPanel is allowed or not, and check that instead.

Rik_Vargard

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

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 Keycode8-0

Well, thank you SO much for everything!!

Khris

You can do this instead:
Code: ags
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

Rik_Vargard

 :-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!! 

SMF spam blocked by CleanTalk