Advanced Script Help

Trying to slim down some scripts and/or put everything into one base script. I've encounter somewhat of a little block.
Instead of using a dozen timers that essentially do the same thing I'm trying to pass the object down through the function call into the sub's but for some reason I can't pass the object name from the function into the respective timer. Any Ideas?

Code: vbscript
  1. Const mskT1="mskTab1"
  2. Const objT1="objTab1"
  3. Dim speed
  4. speed=50
  5. '--Begin Universal Button Functions
  6. '--Left Click Mouse Selection
  7. Function Object_OnLbuttonupEx(obj,x,y,dragged)
  8. With DesktopX
  9.     If Not dragged Then
  10.     Select Case obj.name
  11.         Case objT1
  12.         tBarSlide(mskT1)
  13.     End Select
  14.     End If
  15. End With
  16. End Function
  17. Function tBarSlide(obj)
  18. With DesktopX   
  19.         If .Object(obj).Left >= 0 Then
  20.           object.KillTimer 100
  21.       object.SetTimer 200,speed
  22.     Else
  23.       object.KillTimer 200
  24.       object.SetTimer 100,speed
  25.         End If
  26. End With
  27. End Function
  28. '--Timers
  29. Sub object_ontimer100
  30. With DesktopX.Object(obj)
  31.     If .Left < 0 Then
  32.     .Left = .Left + 5
  33.     Else
  34.     object.KillTimer 100
  35. End If 
  36. End With
  37. End Sub
  38. Sub object_ontimer200
  39. With DesktopX.Object(obj)
  40.   If .Left >=0 Then
  41.     .Left = .Left - 5
  42.   Else
  43.     object.KillTimer 200
  44. End If
  45. End With
  46. End Sub

1,740 views 3 replies
Reply #1 Top
Never mind I found a dirty work-a-round.

Code: vbscript
  1. Const mskT1="mskTab1"
  2. Const objT1="objTab1"
  3. Dim speed,objX
  4. speed=50
  5. '--Begin Universal Button Functions
  6. '--Left Click Mouse Selection
  7. Function Object_OnLbuttonupEx(obj,x,y,dragged)
  8. With DesktopX
  9. If Not dragged Then
  10. Select Case obj.name
  11. Case objT1
  12. tBarSlide(mskT1)
  13. objX=mskT1
  14. End Select
  15. End If
  16. End With
  17. End Function
  18. Function tBarSlide(obj)
  19. With DesktopX
  20. If .Object(obj).Left >= 0 Then
  21. object.KillTimer 100
  22. object.SetTimer 200,speed
  23. Else
  24. object.KillTimer 200
  25. object.SetTimer 100,speed
  26. End If
  27. End With
  28. End Function
  29. '--Timers
  30. Sub object_ontimer100
  31. With DesktopX.Object(objX)
  32. If .Left
  33. .Left = .Left + 5 Else
  34. object.KillTimer 100
  35. End If
  36. End With
  37. End Sub
  38. Sub object_ontimer200
  39. With DesktopX.Object(objX)
  40. If .Left >=0 Then
  41. .Left = .Left - 5
  42. Else
  43. object.KillTimer 200
  44. End If
  45. End With
  46. End Sub
Reply #2 Top
It's because obj is only created within the Object_OnLbuttonupEx and passed on to the function tBarSlide. You need to store the object in a variable in the global script space. Though the problem with that is what happends if the timer get called simultaneously from several objects. They'd then overwrite themself.
Reply #3 Top
They'd then overwrite themself


Yeah, discovered that. So, it would only be acceptable within limited use. Wonder if there is a way to block the call until the previous call is completed?

Edit: I'm wondering if there's a way to set the other objects to inactive. Like a separate sub?