DesktopX Step-By-Step Tutorials #12

Stepping Thru States

By on January 13, 2009 7:23:52 PM from WinCustomize Forums WinCustomize Forums

RomanDA

Join Date 12/2003
+147
Step-by-Step Tutorials

#12 - Stepping Thru States

A series by RomanDA

Listing of other DX Tutorials: Click here

Today's Lesson: "Stepping Thru States" is a very simple way to setup multiple states with a button to change between them.

In this lesson we will cover how to create a simple object, then add multiple states to it, and add a simple button to "step" thru the states.

For this and all the Step-By-Step DX Tutorials you will need to purchase DesktopX for $14.95 from Stardock.

See previous tutorials for how to load DX & create a new object.

Lets get started.

 
STEP 1 - Create the first object "state"
With DX loaded and running, add a new object, goto the "STATES" tab and here we will assign the object a new image and then rename the state to "1"

Browse to the 1st background image you want to use, and select it.
Then use the steps below to rename the state to 1.

RIGHT-Click on the
"Mouse Away" in the States window. 
Click "Rename" and name the state "1".

We will be adding more states in the next step, and each one will be another # .  IE: 2, 3, 4, 5.
 
STEP 2 - Create More States 
Add a new STATE naming it "2" and assigning it to the next background image.

You would continue this for ALL the states you want to add.

In our case we will make the TOTAL 8 states.

Repeat - till you have all 8 states added.

"OK" it all when its done.
 
 
STEP 3 - Adding the code to step thru the states.

Edit the above object and click on "NEW  SCRIPT". We will be adding the following script.

Code: vbscript
  1. Dim MaxStates, CurrentState
  2. 'Called when the script is executed
  3. Sub Object_OnScriptEnter
  4. MaxStates = 2 '-- Set this to the max # of states
  5. '-- Pull Current State from object
  6. CurrentState = Object.PersistStorage("CurrentState")
  7. '-- check CurrentState to see if it had any value
  8. '-- if not set it to 1
  9. If len(CurrentState) = 0 Then
  10. CurrentState = 1
  11. Widget.AddPreference("CurrentState")
  12. Widget.Preference("CurrentState").defaultvalue = 1
  13. End If
  14. Call SetState() '-- See Function Below
  15. End Sub
  16. Function SetState()
  17. object.state = CurrentState
  18. End Function
  19. Sub Object_OnLButtonDown(x, y)
  20. CurrentState = CurrentState + 1
  21. If CurrentState > MaxStates Then CurrentState = 1
  22. Call SetState()
  23. Widget.Preference("CurrentState").value = CurrentState
  24. End Sub
  25. 'Called when the script is terminated
  26. Sub Object_OnScriptExit
  27. End Sub

 

You could also add multiple "state" changes to other objects as well (things like Clock hands, or color changes to text objects, etc.
CONCLUSION
There is a lot more you can do with this, but these are the basic steps to setting up the Stepping Object State Changer.

This works great for clocks, and lots of other items where you want to have multiple looks/colors/layouts.

Enjoy,RomanDA
AKA: David A. Roman
http://romanda.wincustomize.com
29 Replies +2
Search this post
Subscription Options


Reason for Karma (Optional)
Successfully updated karma reason!
January 13, 2009 7:47:04 PM from WinCustomize Forums WinCustomize Forums

Thanks for this Roman, just one question, how do you toggle through the states? is there an option to toggle?

Edit.. I'm an idiot Roman, that WAS for the button doh! <---

Reason for Karma (Optional)
Successfully updated karma reason!
January 13, 2009 8:15:39 PM from WinCustomize Forums WinCustomize Forums

yep.. the whole object is the button.

if you want to make a seperate button somewhere, just look at the code:

Code: vbscript
  1. Sub Object_OnLButtonDown(x, y)
  2.   CurrentState = CurrentState + 1
  3.   If CurrentState > MaxStates Then CurrentState = 1
  4.   Call SetState()
  5.   Widget.Preference("CurrentState").value = CurrentState
  6. End Sub

You would have to make some changes to this to make it work, but its not that hard.  If you download and look at my "Kewl-Klock" it had all of this code in it.

Reason for Karma (Optional)
Successfully updated karma reason!
January 13, 2009 8:26:20 PM from WinCustomize Forums WinCustomize Forums

I've done it dear! just exporting it now, I'm still half asleep, that's my excuse , thanks again for this script, and for suggesting it to me hon, you rock

Reason for Karma (Optional)
Successfully updated karma reason!
Sign Up or Login and this ad disappears!
There are many great features available to you once you register. Sign Up for a free account and browse the forums without ads.
January 14, 2009 9:08:52 AM from WinCustomize Forums WinCustomize Forums

RomanDA feels the Karma

Reason for Karma (Optional)
Successfully updated karma reason!
January 14, 2009 9:06:27 PM from WinCustomize Forums WinCustomize Forums

RomanDA must be related to HG, he also speaks in the third person

Reason for Karma (Optional)
Successfully updated karma reason!
January 14, 2009 9:42:13 PM from WinCustomize Forums WinCustomize Forums

Thanx David. BTW, How's that gadget coming? Or did I miss it's finish?

Reason for Karma (Optional)
Successfully updated karma reason!
January 15, 2009 3:23:28 AM from WinCustomize Forums WinCustomize Forums

RomanDA must be related to HG, he also speaks in the third person

 

HG_Eliminator thinks it must be a Dave thing.

Reason for Karma (Optional)
Successfully updated karma reason!
January 15, 2009 3:32:47 AM from WinCustomize Forums WinCustomize Forums

Tailsgirl means it affectionately

Reason for Karma (Optional)
Successfully updated karma reason!
January 15, 2009 3:41:02 AM from WinCustomize Forums WinCustomize Forums

Very nice!

Reason for Karma (Optional)
Successfully updated karma reason!
January 15, 2009 6:53:50 AM from WinCustomize Forums WinCustomize Forums

 

How's that gadget coming?

RomanDA wonders What gadget? 

RomanDA thinks others should think like he does.

RomanDA likes to use '/ me'

Reason for Karma (Optional)
Successfully updated karma reason!
January 15, 2009 7:01:18 AM from WinCustomize Forums WinCustomize Forums

Tailsgirl is going to test /me out

 

Hey it works!! coolies

Reason for Karma (Optional)
Successfully updated karma reason!
January 15, 2009 11:15:54 AM from WinCustomize Forums WinCustomize Forums

RomanDA wonders What gadget?

Wincustomize Community Wall Gadget, of course!

Reason for Karma (Optional)
Successfully updated karma reason!
January 15, 2009 12:30:41 PM from WinCustomize Forums WinCustomize Forums

oh,  Sorry.. no, it had a lot of issues with screen resolutions, and i just gave up at one point, it was just too time consuming to get working the way i wanted it to.  sorry.. I can send you whats done if you want.

The main issues were with the "desktop" icons not showing with it setup, and that sorta defets the purpose of a "wallpaper"

Reason for Karma (Optional)
Successfully updated karma reason!
January 15, 2009 4:41:09 PM from WinCustomize Forums WinCustomize Forums

Roman couldit be set it up with layered pages like Lcars? one full of the Links as proposed and a second with Desktop Icons available, alternatively switched back and forth with a control button.

Reason for Karma (Optional)
Successfully updated karma reason!
January 15, 2009 5:05:30 PM from WinCustomize Forums WinCustomize Forums

I can send you whats done if you want.
  Please do. I can't script like you do, but I can do a simple wall with the shortcuts and I may have to do several resolutions. I think it can be done with just DX, only not as slick as you were going for. Thanx for giving it a shot!  Jim

Reason for Karma (Optional)
Successfully updated karma reason!
January 15, 2009 5:06:53 PM from WinCustomize Forums WinCustomize Forums

Anything I could do would , of course, require that desktop icons be hidden.

Reason for Karma (Optional)
Successfully updated karma reason!
January 15, 2009 5:08:53 PM from WinCustomize Forums WinCustomize Forums

The main issues were with the "desktop" icons not showing with it setup, and that sorta defets the purpose of a "wallpaper"

What I am proposing will not be a wallpaper, it will be a full screen gadget.

Reason for Karma (Optional)
Successfully updated karma reason!
January 15, 2009 5:46:39 PM from WinCustomize Forums WinCustomize Forums

What I am proposing will not be a wallpaper, it will be a full screen gadget.
My favorite DX desktop . . that was very gadget-y

http://www.wincustomize.com/skins.aspx?skinid=3223&libid=31

Reason for Karma (Optional)
Successfully updated karma reason!
January 15, 2009 5:53:04 PM from WinCustomize Forums WinCustomize Forums

Quoting PuterDudeJim,



What I am proposing will not be a wallpaper, it will be a full screen gadget.

Crikey Jim, you're gonna need some horsepower to push something like that ..... or in my case, I'll need a LOT of extra mice to run in that wheel, that powers my CPU

Reason for Karma (Optional)
Successfully updated karma reason!
January 15, 2009 6:13:58 PM from WinCustomize Forums WinCustomize Forums

I uploaded it here: http://www.wincustomize.com/skins.aspx?skinid=1503&libid=34

its a DXPACK (in a zip file), its also HUGE (size).  Its very complicated in the script, but if you want to take it apart, and try and make it work, its all yours.  I just have not had the time (desire) to make it work.  Maybe VAD could make it work, but i dont know its really a complext thing.

Sorry i never managed to get it 100%.

Reason for Karma (Optional)
Successfully updated karma reason!
January 15, 2009 6:14:00 PM from WinCustomize Forums WinCustomize Forums

Crikey Jim, you're gonna need some horsepower to push something like that ..... or in my case, I'll need a LOT of extra mice to run in that wheel, that powers my CPU

Actually, It shouldn't use any cpu at all. It will just be a wallpaper with built in shortcuts. The problem is in keeping from accidentally using those shortcuts. Probably set to double click. But you won't be able to use it with fences, probably.

Reason for Karma (Optional)
Successfully updated karma reason!
January 19, 2009 3:46:58 PM from WinCustomize Forums WinCustomize Forums

Update:

 

 If you want to change multiple objects with 1 object/button just change the code to show:

Code: vbscript
  1. Function SetState()
  2.   desktopx.object("objname1").state = CurrentState
  3.   desktopx.object("objname2").state = CurrentState
  4.   desktopx.object("objname3").state = CurrentState
  5.   desktopx.object("objname4").state = CurrentState
  6. End Function

Where "objectname1,2,3,4" are the names of the other objects you want to change the state of.

EX: Face,MinHand,HourHand,Background etc.

 

 

If you NAME your objects "Object1" "Object2" "Object3" and so on, you could do the code like this:

Code: vbscript
  1. Function SetState()
  2.  '-- 3 is the max number of objects you have
  3.  for x = 1 to 3
  4.   desktopx.object("objname" & x).state = CurrentState
  5.  next
  6. End Function

Keep in mind that only 1 object needs the code, dont put all this code in every object.
The above tutorial is setup to use the above object as the button as well as the main code.  Again, you could make 1 object a button (like i have in the above tutorial).  Its always best to keep your code in one object.

Before you start messing with code, i would suggest looking over some BASIC Vbscript tutorials, and the first tutorials I created here as well.  Scripting isnt hard, its about knowing what you want to do.

I hope this helps.

Keep in mind that the "State" name needs to be the same on ALL objects.  If you used "1" "2" "3" then they all need to have "1" "2" "3".  if one is missing a state or is named wrong the script will crash.

Reason for Karma (Optional)
Successfully updated karma reason!
January 19, 2009 5:14:11 PM from WinCustomize Forums WinCustomize Forums

Awesome David!!!   It works great!!  People get ready for Chameleon DX!!!! 

Reason for Karma (Optional)
Successfully updated karma reason!
January 19, 2009 7:00:20 PM from WinCustomize Forums WinCustomize Forums

Sweet David, thanks for the update

Reason for Karma (Optional)
Successfully updated karma reason!
January 19, 2009 8:46:53 PM from WinCustomize Forums WinCustomize Forums

glad i can help.

 

now.. i need to beat Zubaz in Karma.. LOL

Reason for Karma (Optional)
Successfully updated karma reason!
Stardock Forums v1.0.0.0    #108433  walnut3   Server Load Time: 00:00:00.0000531   Page Render Time:

Home | About | Privacy | Upload Guidelines | Terms of Service | Help
WinCustomize © 2014 Stardock Corporation. All Rights Reserved.