adding mute function when object is hidden


I'm trying to modify (for personal use) the script in ickypoo's Marvin widget to add a function where the sound is automatically muted when the widget is hidden. I think I know how to do this (I've been reading the DesktopX scripting tutorial), but what I'm doing is not working. Actually, I've tried several different paths to achieve this, including using ObjectOnStateChange calls to detect whether the object is hidden or shown. This is what the latest iteration of modification looks like:

Object.PersistStorage("soundNUM") = 1
'Called when the script is executed
Sub Object_OnScriptEnter
Object.SetTimer 99384, 25
Object.SetTimer 98994, 60000
End Sub

'Called when the script is terminated
Sub Object_OnTimer99384
Object.Left = Object.Left + 1
If Object.Left > System.ScreenWidth Then Object.Left = - Object.Width
End Sub

Sub Object_OnTimer98994
Object_OnMouseEnter()
Object_OnShow(IsVisible)
End Sub

Sub Object_OnShow(IsVisible)
If IsVisible = True Then
Object.Volume = 85
Else
Object.Volume = 0
End If
End Sub

Sub Object_OnMouseEnter
Object.ToolTipText = "Playing marvin" & Object.PersistStorage("soundNUM") & ".wav"
Object.Sound = "marvin" & Object.PersistStorage("soundNUM") & ".wav"
Object.PersistStorage("soundNUM") = Object.PersistStorage("soundNUM") + 1
If Object.PersistStorage("soundNUM") > 16 Then Object.PersistStorage("soundNUM") = 1
End Sub


Could someone here who's really clever with scripting give me a pointer or two? I've just started trying to tinker with this, and I may be overlooking something dumb. Thanks.

2,483 views 9 replies
Reply #1 Top
Wait a several minutes. I download it...
Reply #2 Top
Hmmm... I never use the PersistStorage (don't like it...). However I maked something... It works nearly as you want.

First of all you need rename the "Mouse away" state to "silent" add one more state "sound" into the Marvin. Then:

1. Copy the "marvin.ani.PNG" from "silent" to "sound" and apply the same animation.
2. Remove the "marvin6.wav" file from the "silent" state and paste it to the "sound" state.
3. Create new text object "test" on the desktop.

Paste this code into the Marvin:

Dim lborder,rborder

'Called when the script is executed
Sub Object_OnScriptEnter
lborder = -1
rborder = -1
Object.state = "silent"
Object.PersistStorage("soundNUM") = 0
object.left = System.VscreenLeft - Object.width * 2
Object.SetTimer 1, 25
Object.SetTimer 2, 60000
End Sub

'Called when the script is terminated
Sub Object_OnTimer1
lborder = Object.right - System.VscreenLeft
rborder = System.ScreenWidth - Object.right
If lborder = 0 Then
Object.state = "sound"
Object.PersistStorage("soundNUM") = 6
Object.Sound = "marvin" & Object.PersistStorage("soundNUM") & ".wav"
End If
If rborder = 0 Then
Object.PersistStorage("soundNUM") = 7
Object.Sound = "marvin" & Object.PersistStorage("soundNUM") & ".wav"
'Object.state = "silent"
End If
'
Reply #3 Top

Vad_M,

I'll have to try this when I get home later. Thanks for taking the time to help a scripting newbie.   

Reply #4 Top
No any problems. I much respect people who want to study DX scripting and try to create something new on their desktops.    And I'm always ready to help them.
Reply #5 Top
Hey, Vad_M, I tried out your script example. I think you may have misunderstood what I was asking. I see that your script uses the test object to display the screen x and y of the marvin.walking object and the sound it is currently set to play. Also, if I'm reading it right, it appears that it disables the sound when the marvin.walking object is not visible on screen; in other words, when it has "walked" off-screen. However, what I was looking for was something that would mute the object volume when the object's state was set to "Hide" and reenable it when it is set to "Show." I've tried using Object_OnStateChange coupled with an if-then statement like this: If ObjectState="Hide" Then Object.Volume = 0 Else Object.Volume = 85 End If. However, this doesn't seem to work. Do you have any suggestions? Thanks.
Reply #6 Top
Hi, warreni. How are you hiding/showing the widget? I set up a couple of objects; one has a message to hide Marvin on mouse up, and another object has a message to show Marvin on mouse up. Then, I gave Marvin a "Show" state and copied the properties of the "mouse away" state to the "Show" state. I also gave Marvin a "Hide" state (be sure to assign an image for the hide state; it won't work otherwise). Here's a pic:




Finally, I inserted this piece of code to the script.

Sub object_onstatechange(state)
If state = "Show" Then
system.Volume = 85
ElseIf state = "Hide" Then
system.Volume = 0
End If
End Sub

So basically, the widget needs to have a "Show" state and a "Hide" state. (Both states should be assigned images). Then insert the script. I'm not sure what method you are using to hide and show Marvin and if this will work with that.
Reply #7 Top
Sorry i was offline some time... You are absolutely right. I'm really has not understood you. So I have thought that you wanted to listen sound only when Marvin is visible on the screen...

You may use code that advises sVis. It will work nice.

The second way - you may use the "WMPlayer.OCX" ActiveX object to do this (use Google to find info about). You will not touch the system volume in the last case.

Best Regards.
Reply #8 Top
When I first read this I thought, "How funny would it be if marvin was set on the desktop level and walked BEHIND a window if the volume went down as if mufled by the window".

Is that possible?
Reply #9 Top
I'll take a stab at sViz's suggestion. FYI, I was (and maybe this is doing things the dumb/hard way?) manipulating the state by using the systray icon (in other words, not during testing, but got out of DesktopX Builder altogether and ran the widget in the runtime environment).

Zubaz- yes, this is probably possible through manipulating the Z-order, but hey, man, I'm just trying to figure out hide and show right now!