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()
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:
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;
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.
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
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();
}
}
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
Try leaving it out and see what happens.
I mean, if you just look at the code, you will notice that you have this:
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:
// 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();
}