-SOLVED- Need help with scripting animation

My code doesn't work

I'm trying to set up an animation to play when I click on it, then wait about 5 seconds, and then return to it's original state.  Here's what I have so far:

 

Code: vbscript
  1. 'Called when the script is executed
  2. Sub Object_OnScriptEnter
  3. End Sub
  4. Sub Object_OnStateChange(state)
  5.     If state = "Mouse Down" Then
  6.       Object.SetPicture "YinYangAnimStrip.bmp",28,50,&H0000008
  7.         Object.SetTimer 1, 5000
  8.     End If
  9. End Sub
  10. Sub Object_OnTimer1
  11.   Object.SetPicture "IMG00000.bmp",1,50,&H00000008
  12.   Object.KillTimer 1
  13. End Sub
  14. 'Called when the script is terminated
  15. Sub Object_OnScriptExit
  16. End Sub

 

The code won't work for me, so I must be doing something wrong.  Can someone help me out?

Thanks :D

6,117 views 9 replies
Reply #1 Top

Try changing the capital 'D' in Mouse Down to a lowercase 'd'. For default states, the syntax must be exact.

 

 

Reply #2 Top

Still doesn't work.

Here's what I have right now:

 

Code: vbscript
  1. 'Called when the script is executed
  2. Sub Object_OnScriptEnter
  3. End Sub
  4. Function Object_OnLButtonUp(x, y, Dragged)
  5.   If Dragged = False Then
  6.       Object.SetPicture "YingYangAnimStrip.bmp",28,50,&H0000008
  7.           Object.SetTimer 1, 5000
  8.   End If
  9. End Function
  10. Sub Object_OnTimer1
  11.   Object.SetPicture "IMG00000.bmp",1,50,&H00000008
  12.   Object.KillTimer 1
  13. End Sub
  14. 'Called when the script is terminated
  15. Sub Object_OnScriptExit
  16. End Sub

Reply #3 Top

Hmm. Are these images included anywhere in your theme/widget/object? Unless they're included somewhere (Custom files, or attached to an object state,) DX won't copy them to the object directory where you can use the short form "YinYangImage.bmp".  Otherwise, you would need to use the full path, e.g., "C:\YinYangImage.bmp"

Reply #5 Top

That's odd. I'm using your exact script and it works. How's your object setup? Does it have multiple states?

What version of DX do you have? I know of at least one DX script--Object.SetScript--that does not work for older versions (pre 3.2)

Reply #6 Top

Running version 3.5

 

The object has a default state with the appearance set to IMG00000.bmp and running the script I entered above.

Reply #7 Top

Update:

I created a new object and set it's appearance.  I then added the script and it sorta worked.  Here's what it needs to do:

3 Stages of animation

Stage 1 - Still image

Stage 2 - Animated Forward

Stage 3 - Animated Backward

The order should be, Stage 1 until clicked, then Stage 2 for 5 seconds, then Stage 3, and finally stage 1 again until clicked once more.

What's happening is this: Stage 1 until clicked, then Stage 2 for 5 seconds, then Stage 1 again until clicked, then it goes to the last frame in Stage 2 for 5 seconds, Stage 1, repeat.

Is something wrong with the script?  Here's what I have so far:

Code: vbscript
  1. Sub Object_OnScriptEnter
  2.  End Sub
  3.  Function Object_OnLButtonUp(x, y, Dragged)
  4.    If Dragged = False Then
  5.        Object.SetPicture "YingYangAnimStrip.bmp",28,50,&H0000008
  6.        Object.SetTimer 1, 5000
  7.    End If
  8.  End Function
  9.  Sub Object_OnTimer1
  10.    Object.SetPicture "YingYangAnimStrip.bmp",28,50,&H0000002
  11.    Object.KillTimer 1
  12.  End Sub
  13.  Sub Object_OnScriptExit
  14.  End Sub

Reply #8 Top

Figured it out.  The DesktopX resources under the Help section said that &H0000002 was Reverse, but changing it to &H0000004 caused it to reverse.  I don't know if I'm misunderstanding the word "reverse", but I got it working now.  The script is exactly as above, only with &H0000004 instead of &H0000002.

 

Thanks for the help :D

Maybe someone will find the answer useful :D

Edit:  Also had to change &H0000008 to &H0000006 to stop it from going to the last frame of Stage 2.

Reply #9 Top

Glad you got it sorted out. :thumbsup: