Buttons GetAtScreen problem

Started by Slasher, Sat 18/01/2014 08:59:14

Previous topic - Next topic

Slasher

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

  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

  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;




Dualnames

Code: ags

  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

  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

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();
}
}
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Slasher

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

Khris

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
 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
// 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();
  }

SMF spam blocked by CleanTalk