Sound on gui rollover

Started by Mel_O_Die, Mon 16/10/2006 22:54:45

Previous topic - Next topic

Mel_O_Die

Hi!

I want to play a little buzz when the mouse activates a GUI butto's mouseover mode

how can i do that?  ??? ???

thanks!
----( )----
Click to see "In Production" Topic!
[/color][/b][/url]

Theeph

#1
Hiya.

You'll need to use a piece of code like this:

Code: ags

GUIControl *theControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
if (theControl == lstSaveGames) {
  // The mouse is over the Save Games list box.
}
else if (theControl == null) {
  // The mouse is not over a control.
}
else {

  GUI *onGui = theControl.OwningGUI;
      
     if(theControl.ID == 1)    // if the mouse is over control number 1
     {
        PlaySound(1);        // play the appropriate sound for control 1
     }
 
     else if(theControl.ID == 2)
     {
             // keep going until you run out of buttons to attach sounds to.
     }

}




I don't know how much of a good idea this next bit is, but it will work:

Paste the above into your global script inside the #repeatedly_execute section.

Something like this:

Code: ags

#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() 
  {

        if(gYourGuiHere.visible == true)
               {
                    <<put the above code in here>>
               }
  }


Hope that helps. PM if you can't get it to work.

Mel_O_Die

thanks very much! that works fine!

(i hade just to fix a thing because with your method the sound is looped :) )
----( )----
Click to see "In Production" Topic!
[/color][/b][/url]

Theeph

Oops. Sorry for the loopage.

Glad it worked.

Khris

#4
You didn't post the adjusted code, but this should shorten it:

Code: ags
function repeatedly_execute_always() {
  GUI*g=GUI.GetAtScreenXY(mouse.x, mouse.y);
  if (GUI==xxx) {   // replace xxx with GUI's name
    GUIControl*gc=GUIControl.GetAtScreenXY(mouse.x, mouse.y);
    if (IsSoundPlaying()==0 && gc.AsButton!=null) PlaySound(x);  // replace x with sound's number
  }
}


Edit: Won't work as intended, see below.

Mel_O_Die

#5
Quote from: KhrisMUC on Tue 17/10/2006 19:40:33
You didn't post the adjusted code, but this should shorten it:

Oh yesÃ,  ::) excuse me :)

for doing that i used a globalint initially set as "0" and changed to "1" when the sound is played once and after i reset the global int when the mouse is not over a control :)

Code: ags


GUIControl *theControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);

if (theControl == null) { // The mouse is not over a control.
Ã,  SetGlobalInt(101, 0); // sets the globalint to 0
}

if (GetGlobalInt(101)==0){Ã,  //check the global int
Ã,  Ã, if (gYOURGUI.Visible){
Ã,  Ã,  Ã,  if((theControl.ID == 2)||(theControl.ID == 5)||(theControl.ID == 7)||(theControl.ID == 3)||(theControl.ID == 6))Ã, { Ã,  // if the mouse is over controls number 2,5,7,3,6
			
Ã,  Ã,  Ã,  Ã, Ã,  SetGlobalInt(101, 1);Ã,  // sets the globalint to 1 for play sound once
Ã,  Ã,  Ã,  Ã, Ã,  PlaySound(9);Ã,  Ã,  Ã,  Ã,  // play the appropriate sound for controls
Ã,  Ã,  Ã,  }
Ã,  Ã, }
}



I will try with your method who seems easier :)

and i've an other question, what's the difference between
function repeatedly_execute_always() {
and
function repeatedly_execute() {


i've all my scripts who needs to be executed each frame in the simply execute, what the allways can give to me?
----( )----
Click to see "In Production" Topic!
[/color][/b][/url]

GarageGothic

The repeatedly_execute_always runs also during blocking functions (characters talking, some walk modes) while the normal repeatedly_execute doesn't. I assume the player can't use the interface during such scenes, so I would assume the normal repeatedly_execute should be enough in your case.

Theeph

Quote from: KhrisMUC on Tue 17/10/2006 19:40:33
Code: ags
function repeatedly_execute_always() {
  GUI*g=GUI.GetAtScreenXY(mouse.x, mouse.y);
  if (GUI==xxx) {   // replace xxx with GUI's name
    GUIControl*gc=GUIControl.GetAtScreenXY(mouse.x, mouse.y);
    if (IsSoundPlaying()==0 && gc.AsButton!=null) PlaySound(x);  // replace x with sound's number
  }
}


Won't that still repeat the sound over and over?

IsSoundPlaying() will see if there is a sound currently playing but if the sound finishes won't it just start up again? May not be a problem if the button sound is a full length song or anything, but if it's a half-second blip it'd still seem to loop.

Or am I missing something?

If not - is there any way apart from globalInts to get the off switch to work?

Khris

#8
Of course, you're right.
Global Ints are completely redundant, you can always use "script-ints" or pointers, like this:

Code: ags
Button*oldb; // pointer holding current/old button

function repeatedly_execute() {
  GUI*g=GUI.GetAtScreenXY(mouse.x, mouse.y);
  if (GUI==xxx) {   // replace xxx with GUI's name
    GUIControl*gc=GUIControl.GetAtScreenXY(mouse.x, mouse.y);
    Button*b=gc.AsButton;
    if (b!=null && b!=oldb) {
      PlaySound(x);  // replace x with sound's number
      oldb=b; // set old button to current one
    }
  }
}

Theeph

Hmm... I like the use of data encapsulation versus the global system.

I've recently been scripting with 2.62 as well as another project with 2.72. It's right about here it gets confusing.

Cheers though. Good tip.

SMF spam blocked by CleanTalk