Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Slasher on Sat 18/01/2014 08:59:14

Title: Buttons GetAtScreen problem
Post by: Slasher on Sat 18/01/2014 08:59:14
Hi,

I have made a bool scream_play and put it at the top of the Global and have it as false.

In Global repeatedly_execute()

Code (ags) Select

  if (Button.GetAtScreenXY(mouse.x, mouse.y) == Button16 && scream_play==false) {
  scream_play=true;
  if(scream_play==true){
  aSplash_Laugh.Play();
  scream_play=false;


This works fine but it does not seem to take  || as well as bool when adding other Buttons in the equation.

What I am trying to do is add if Button17, Button18 or Button19 as well as Button16.

Would you give me a hand please?

cheers

EDIT I am having to use this at the moment:
Code (ags) Select

  if (Button.GetAtScreenXY(mouse.x, mouse.y) == Button16)
  scream_play=true;
  if(scream_play==true){
  aSplash_Laugh.Play();
  scream_play=false;
  }
  else if (Button.GetAtScreenXY(mouse.x, mouse.y) == Button17)
  scream_play2=true;
  if(scream_play==true){
  aSplash_Laugh.Play();
  scream_play=false;
  }
  else if (Button.GetAtScreenXY(mouse.x, mouse.y) == Button18)
  scream_play=true;
  if(scream_play==true){
  aSplash_Laugh.Play();
  scream_play=false;
  } 
  else if (Button.GetAtScreenXY(mouse.x, mouse.y) == Button19)
  scream_play=true;
  if(scream_play==true){
  aSplash_Laugh.Play();
  scream_play=false;



Title: Re: Buttons GetAtScreen problem
Post by: Dualnames on Sat 18/01/2014 09:21:07
Code (ags) Select

  if (  (Button.GetAtScreenXY(mouse.x, mouse.y) == Button16 ||  Button.GetAtScreenXY(mouse.x, mouse.y) == Button17||  Button.GetAtScreenXY(mouse.x, mouse.y) == Button18||  Button.GetAtScreenXY(mouse.x, mouse.y) == Button19)   &&  scream_play==false) {
  scream_play=true;
  if(scream_play==true){
  aSplash_Laugh.Play();
  scream_play=false;
}


However the way you use scream_play variable here, it seems apparent that you don't need the variable. The code below would work in the same way.

Code (ags) Select

  if (  (Button.GetAtScreenXY(mouse.x, mouse.y) == Button16 ||  Button.GetAtScreenXY(mouse.x, mouse.y) == Button17||  Button.GetAtScreenXY(mouse.x, mouse.y) == Button18||  Button.GetAtScreenXY(mouse.x, mouse.y) == Button19))
{
  aSplash_Laugh.Play();
}
}


and you could also make the code easier to read
Code (ags) Select

GUIControl *gui_control= GUIControl.GetAtScreenXY(mouse.x, mouse.y);
  if (  (gui_control == Button16 ||  gui_control == Button17||  gui_control== Button18|| gui_control == Button19))
{
  aSplash_Laugh.Play();
}
}
Title: Re: Buttons GetAtScreen problem
Post by: Slasher on Sat 18/01/2014 10:10:02
Cheers  Dualnames

The reason I have a variable is to turn sound Splash_Laugh on only if boolean is true as it is in Rep Exec.

I will look into what you have put ;)

Thanks
Title: Re: Buttons GetAtScreen problem
Post by: Khris on Sat 18/01/2014 14:27:29
Try leaving it out and see what happens.
I mean, if you just look at the code, you will notice that you have this:
Code (ags) Select
scream_play=true;
  if(scream_play==true){
  ...// code X
  }

Can you think of a situation in which code X is not run...?

What you probably want is this:
Code (ags) Select
// above the function
AudioChannel *scream;

  //inside
  if (scream == null || !scream.IsPlaying) {
    GUIControl *gc = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
    if (gc == Button16 || gc == Button17 || gc == Button18 || gc == Button19) scream = aSplash_Laugh.Play();
  }