DesktopX: Scripting Visibility (Beginner)

From WinCustomize Wiki

Jump to: navigation, search


Scripting Visibility
Original Author:sViz
Date Created:August 24, 2007
Application:DesktopX
Programs Used:DesktopX


In this quick tutorial we'll look at how to change the visibilty of your object through scripting.

Contents

[edit] Changing Visibility

There are two ways to control whether or not an object is visible. You can change visibility or you can change opacity. Which one you choose to change will depend on how you want to show/hide your object.

[edit] Visibility

To change an object’s visibility you would simply give it a true or false value; true being visible and false being not visible.

Object.visible = true

[edit] Opacity

If you don’t want to mess with visibility (sometimes you might need a work around) then opacity is the way to go. With opacity you’re only changing the transparency of the object, allowing you to give your object different degrees of visibility. 100 = fully visible, 50 = half transparent, 0 = completely transparent.

Object.opacity = 100

[edit] OnShow

The OnShow procedure is a procedure that is called when the object’s visibility changes. So if you need to do something when the object becomes visible or not visible this is where you’d write it.

'Called when object's visibilty changes
Sub Object_OnShow(IsVisible)
	If IsVisible= True Then
		msgbox "The object is visible!"
	ElseIf IsVisible = False Then
		msgbox "The object is NOT visible!"
	End If
End Sub

[edit] Fading

Since controlling visibility is relatively straightforward, we have some extra time on our hands to script a relatively simple fading visibility effect. Here, the object will continuously fade in and out. We’ll be using a timer to change object.opacity.

Create a new object and then create a new script.

First we need to declare our variable and set the object’s starting opacity.

Dim fade

'Called when the script is executed
Sub Object_OnScriptEnter
	object.Opacity = 100
	fade = "out"
	object.SetTimer 1,10
End Sub

With the variable ‘fade’ we can tell whether our object is fading in, in which case we need to increase opacity, or fading out and we need to decrease opacity. We’ve got 2 conditions so naturally we’ll need conditionals to discern which action to take.

Sub Object_OnTimer1
	Select Case fade
		Case "out"
			If object.opacity =< 0 Then
				fade = "in"
			Else
				object.opacity = object.opacity - 1
			End If
		Case "in"
			If object.opacity => 100 Then
				fade = "out"
			Else
				object.opacity = object.opacity + 1
			End If
	End Select
End Sub

I’ve used the Select Case and If Else statements to, first, check which way we’re fading and, second, when to switch the fading direction. That's it.

Next Tutorial: DesktopX: Scripting Motion (Beginner)

[edit] Tips

  • If you want to make the fading effect go slower or faster I’d suggest changing the timer speed, but if you want to change the increment amount, use a number that will add up to 100 exactly. Opacity does some strange things when you go over 100 or below 0.

[edit] Further Reading