A Newbie's Guide to DesktopX Scripting, Part 1
Making A simple Rollup Button.
A Newbie's Guide to DesktopX Scripting, Part 1. (Making A
simple Rollup Button.)
| In the last few months I have finally had the chance to
start learning to do some DesktopX scripting. This is something I have been
interested in doing since DesktopX first started supporting scripts. Back in the
days before i spent all my time on Icons, I spent it all on DesktopX. I made
more Zoomers then I can remember, and several complete themes, all of which need
to be updated. But I never got the chance to learn to script.
One of the major perks to working at Stardock, for me a least, is that I work write next to several great programmers. This however has awakened a my long set aside itch to learn to code, and not wanting to change carriers at this late point in my life, DesktopX scripting has presented itself as the perfect why for me to scratch it. So with allot of question asking, and allot of looking at other peoples code, mostly Tiggs, _Martin_, and Brazon_Weep. I have started to learn. As I began my learning process I was struck by a few
things. First, How much is possible with DesktopX when you start adding scripts.
Second, how many people write the code to be used only in that one object. The
first fact got me addicted to DX scripting in about a day. The second fact, made
me want to learn to do it right. As I said, I work with several great
programmers, most of which are as anal about coding, as I am about design. So I
am constantly observing, what i will call, and I am a coding Newbie, good
programming habits. So as I learn I am trying to fallow a few guidelines that I
have picked up from them. and they are. Never Hard Code variables, if at all possible. This helps your code be reusable. For yourself and others. Write Modularly. This is just good practice all around. An my main point. of this Tutorial. Quickly I will point out, that I am a total newbie, and
allot of what I am going to lay out here will probably seem obvious or wrong, to
experienced programmers, but this is not for them, this is for people like
myself, that love to skin, and always thought, I could do "this" if I new how to
script. Well I'm learning, and I thought maybe a few others would want to come
along for the ride. First lets start with the code: |
|
| '**************************************************************************************************************** '************* Sample_Rollup_Button ************ '**************************************************************************************************************** Dim ulRolledUpSize Dim ulExpandedSize Dim ulSpeed ulRolledUpSize = 32 'This sets the size you want your parent object to rollup to. ulExpandedSize = 250 'This sets default the size you want your parent object to rolled down ulSpeed = 20 'This sets the # of frames you want it to take to role up or down '**************************************************************************************************************** Sub Object_OnLButtonDown(x,y) 'When this object is clicked. If Object.StatePreempt = "Up" Then 'Check to see if we are Rolled Down. Rollup() 'If it is, Call the Rollup sub. Else 'If Not Rolldown() 'Call the Rolldown Sub. End If End Sub '**************************************************************************************************************** Sub Rollup() ulExpandedSize = Object.Parent.Object.Height 'Set the current size as the Expanded size Object.StatePreempt = "Down"
'Change the image state to 'down' '**************************************************************************************************************** | |
|
Let me quickly point out, that all this code goes in the Rollup/Down Button. However most the time it is effecting its Parent. As I describe what I am doing here I will refer to the Button Object as 'the Button' and the Parent Object as 'The Parent Object' . Note; For some reason, and it may be a bug, at the time I am writing this, you need to have a script in the parent object, in order to call it with Object.parent, it can be, and In this example is, blank. This Code is pretty simple, and I will go over it and
explain what is happening. The first thing I might Point out, is that I have
divided up all the Sub with '******* this is to make
it easier to read, and make it seam more modular. In fact it would make no
difference to the code if I did not do this. I have also tried really hard to
comment as much as possible, this once again is a good
practice | |

) guides like this makes it even quicker for me to pick up.