Your DesktopX Documentation Resource Guide

Documentation Home

Quick Start

User's Guide

Developer's Guide

Resources

Tutorials


By now you should realize just w

DesktopX Scripting

By now you should realize just what amazing results can be achieved using DesktopX. DXScript takes things to an entirely new level!

Whilst DesktopX is flexible, DXScript allows a user with a hint of programming experience to really extend the possibilities of what you can do.

DXScript allows you to program in either VBScript and JScript, two of the most simple and common languages available. This document is not designed to teach you how to program these languages, we assume you know the basics. If not, I suggest you take a little time to learn and then you can join the fun. Before you recoil in fear at the works 'programming' and 'script', this is not a trip into the world of the uber-geek. Let me say this once and say it loud - "Learning DXScript is not hard!".

Adding script to objects is very easy. Simply open up the Object Properties dialogue of the object to which you want to add script and on the General tab you will see a button saying 'New' in the Script section. Clicking this brings up the dialogue you see on the left. You will note that the main window is prepared for you to start entering script, but before we do that let's look around the 'Script' menu. Under this there are three sections. The second one, 'Language' allows you to specify whether you want to program in VBScript or JScript.

Whilst both work in pretty much the same way, we will be using VBScript examples here. Once you have decided on a Scripting language you are ready to go. This is where you start to need a bit of scripting or programming knowledge. As with most programming languages, everything is based around a series of Events and then Methods and Properties are used to make things happen. By default two events are created. You will also see comment lines (starting with ' ) that explain when they occur. So lets get scripting straight away in the traditional way! Edit the script to display the following:

Sub Object_OnScriptEnter
MsgBox "Hello, World!"
End Sub

Sub Object_OnScriptExit
MsgBox "So Long, And Thanks For All The Fish!"
End Sub

Note that the indents on the code are just for clarity.

If you now close the script you will now have an object the pops up a message every time the script is enabled or disabled.

OK, so this is a bit fake because you're enabling the script and disabling script, but in the real world this will pop up a message when DesktopX loads (and the object's script is enabled), and a message when DesktopX unloads (and the object's script exits).

One of the other key Events is Object_OnStateChange(state). This identifies when an object switches from one state to another and allows script to be run at that time. By querying the state that has arisen, script can be run in response to that.

In the below example, the script pops up a message if the user activates the object (the 'Command executed' state).

Sub Object_OnStateChange(state)
    If state = "Command executed" Then
        MsgBox "You activated me!"
    End If
End Sub

Note that you can also check for Custom Messages, and not just the default states that exist. The final state that needs discussing here is the Object_OnTimer event. DesktopX can create timers which mean that script can be run at set intervals. Although we will be discussing object methods later, we need to use one here. Before a timer event can run you need to define that timer by using an Object.SetTimer command. In this command you give the timer a unique numeric identifier and specify the interval (in milliseconds) at which the timer will run.

In the below example a timer with the identifier 12345 is set up when the script starts to run every 10 minutes (600000 milliseconds). Each time this timer occurs, the script flashes up the current time using the VBScript command Time().

Sub Object_OnScriptEnter
Object.SetTimer 12345, 600000
End Sub

Sub Object_OnTimer12345
  MsgBox "The time is " & Time()
End Sub

Sub Object_OnScriptExit
  Object.KillTimer 12345
End Sub

Now that we have discussed events, obviously you can use any VBScript or JavaScript within an event, but to properly interact with DesktopX you need specific Methods and Properties.

More detail and examples are also available in the DXScript Reference, but we will discuss some of the basics here to get you started. To start with you need to know how to refer to objects and then we'll move onto the things you can do with them. To refer to the current object (i.e. the one who's script you are editing), simply use Object.xxxx.

For example:

Object.Left = 200

To refer to another object in the theme you use DesktopX.Object("ObjectName").xxxx.

For example:

DesktopX.Object("Button").Left = 200

Note that some objects may have multiple states. Where this occurs, DXScript allows you to adjust parameters for some or all of these states. This is further explained in the Object Namespace reference.


7/29 

SkinStudio 6.2 Released

7/25 

A God Has Fallen - New Demigod Trailer Released

7/24 

Sins of a Solar Empire v1.1 Beta has Arrived

7/23 

Stardock Releases New WindowBlinds 6.2 Update

7/22 

Stardock Releases The Political Machine v1.04 with New Characters

7/22 

Stardock Releases MyColors 2.5

7/17 

DesktopX 3.5 Officially Released

7/11 

Corel WinDVD 9 and Painter X Now Available on Impulse!