Home Technical Talk
The BRAWL² Tournament Challenge has been announced!

It starts May 12, and ends Sept 12. Let's see what you got!

https://polycount.com/discussion/237047/the-brawl²-tournament

Maxscript need help: integer to frame

hey,
i'm currently making a 'walkcycle-creator' maxscript
and i just faced my first big problem:
i can't find how i convert an integer into a frame :s
so i have this timespinner in which you can set the number of frame's for a walk-loop
wcci.jpg
so i would like to get the integer from the spinner and convert it into frames so i can use it in the slidertime to set keys.
here's the code i have so far
codei.jpg

thanks in advance,
Sandeir

Replies

  • r_fletch_r
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    You probably just need to cast the vale as a time value.
    1. timeValue = ( spinner.value as time )
  • Sandeir
    hmm no sorry that doesn't seem to de the trick, but thanks anywhay,
    because when my Timespinner value is 24 an i want to set a key at the 12th frame i would type "timeslider = (tijd/2)f" and ik give's an error :s
    it's probably easy'er if i just add my code, sorry
    1. rollout WalkcycleCreator "WalkcycleCreator" width:224 height:272
    2. (
    3. spinner TijdSpinner "Timespinner" pos:[10,30] type: #integer width:200 height:44 range: [12, 36, 0]
    4. slider TypeSlider "small - normal - cartoony" pos:[20,100] width:200 height:44
    5. button btnCreate "Create" pos:[20,180] width:100 height:50
    6. on btnCreate pressed do
    7. (
    8. framerate = 25
    9. --Create Biped---------------------------------------------------------------------
    10. Bip001 = biped.createNew 170 -90 [0, 0, 165] spineLinks: 2
    11. --------------------------------------------------------------------------------------
    12. typeAnimatie = TypeSlider.value
    13. print typeAnimatie
    14. lengteAnimatie = TijdSpinner.value
    15. print lengteAnimatie
    16. --tijd = TijdSpinner.value
    17. tijd = ( TijdSpinner.value as time )
    18. print tijd
    19. animationRange = interval 0 12
    20. with animate on
    21. (
    22. toolmode.coordsys #local
    23. slidertime = 0f
    24. select $Bip001
    25. move $ [0, 0, -20]
    26. rotate $ (angleaxis 5 [0,1,0])
    27. rotate $ (angleaxis 20 [0,0,1])
    28. select $'Bip001 R Foot'
    29. --move $ [0, -30, 10]
    30. move $ [10,-40,10]
    31. rotate $ (angleaxis -20 [0,0,1])
    32. rotate $ (angleaxis -5 [0,1,0])
    33. rotate $ (angleaxis -30 [1,0,0])
    34. biped.SetSlidingKey $'Bip001 R Foot'
    35.  
    36. slidertime = (tijd/2)f
    37. select $Bip001
    38. move $ [0, 0, 10]
    39. select $'Bip001 R Foot'
    40. move $ [0, 50, 0]
    41. biped.SetSlidingKey $'Bip001 R Foot'
    42. )
    43. )
    44. )
    45. --1) create biped
    46. --2) kies type (slider)
    47. --3) kies lengte (aka snelheid)
    48.  
    49.  
    50. CreateDialog WalkcycleCreator
    51. --addRollout WalkcycleCreator
  • monster
    Offline / Send Message
    monster polycounter
    You don't need the "f" when setting sliderTime. You can just say:

    slidertime = (tijd/2)

    If you run into a situation where you do need the integer as a frame number you can convert it using "as time"

    slidertime = (tijd/2) as time

    The trickier situation is converting a frame to an integer. For example,

    60f as integer
    --Result: 11520

    (60f as integer)/ticksperframe
    --Result: 60

    For some reason, the result is in ticks and not frames. But if you divide by the global variable ticksperframe you get the number you are looking for. Luckily, just like slidertime accepts an integer, most things that require and integer can be fed a frame number.
  • Sandeir
    it still doesn't do hat it's suppose to do :s
    1. tijd = TijdSpinner.value
    2. animationRange = interval 0 12
    3. with animate on
    4. (
    5. toolmode.coordsys #local
    6. slidertime = 0
    7. select $Bip001
    8. move $ [0, 0, -20]
    9. rotate $ (angleaxis 5 [0,1,0])
    10. rotate $ (angleaxis 20 [0,0,1])
    11. select $'Bip001 R Foot'
    12. --move $ [0, -30, 10]
    13. move $ [10,-40,10]
    14. rotate $ (angleaxis -20 [0,0,1])
    15. rotate $ (angleaxis -5 [0,1,0])
    16. rotate $ (angleaxis -30 [1,0,0])
    17. biped.SetSlidingKey $'Bip001 R Foot'
    18.  
    19. slidertime = (tijd/2) as time
    20. select $Bip001
    21. move $ [0, 0, 10]
    22. select $'Bip001 R Foot'
    23. move $ [0, 50, 0]
    24. biped.SetSlidingKey $'Bip001 R Foot'
    25. )

    it's suppose to set key at frame 6, but is doesn't :/
  • monster
    Offline / Send Message
    monster polycounter
    This is odd, but the problem is that you set the range for TijdSpinner to [12, 36, 0]. The last number 0 is the current value of the spinner even though it displays 12. You can just set the range to [12, 36, 12] and it works.
  • Sandeir
    hey monster thanks that helped a lot !!!

    my code looks like this at the moment:
    1. rollout WalkcycleCreator "WalkcycleCreator" width:224 height:272
    2. (
    3. spinner TijdSpinner "Timespinner" pos:[10,30] type: #integer width:200 height:44 range: [12, 36, 12]
    4. slider TypeSlider "small - normal - cartoony" pos:[20,100] width:200 height:44
    5. button btnCreate "Create" pos:[20,180] width:100 height:50
    6. global tijd = TijdSpinner.value
    7. on TijdSpinner changed value do
    8. (
    9. animationrange.start = 0
    10. animationrange.end = tijd as time
    11. )
    12. on btnCreate pressed do
    13. (
    14. framerate = 25
    15. --Create Biped---------------------------------------------------------------------
    16. Bip001 = biped.createNew 170 -90 [0, 0, 165] spineLinks: 2
    17. --------------------------------------------------------------------------------------
    18. typeAnimatie = TypeSlider.value
    19. --tijd = TijdSpinner.value
    20. print tijd
    21. with animate on
    22. (
    23. --
    24. toolmode.coordsys #local
    25. slidertime = 0
    26. select $Bip001
    27. move $ [0, 0, -20]
    28. rotate $ (angleaxis 5 [0,1,0])
    29. rotate $ (angleaxis 20 [0,0,1])
    30. select $'Bip001 R Foot'
    31. --move $ [0, -30, 10]
    32. move $ [10,-40,10]
    33. rotate $ (angleaxis -20 [0,0,1])
    34. rotate $ (angleaxis -5 [0,1,0])
    35. rotate $ (angleaxis -30 [1,0,0])
    36. biped.SetSlidingKey $'Bip001 R Foot'
    37.  
    38. slidertime = (tijd/2) as time
    39. select $Bip001
    40. move $ [0, 0, 10]
    41. select $'Bip001 R Foot'
    42. move $ [0, 50, 0]
    43. biped.SetSlidingKey $'Bip001 R Foot'
    44. )
    45. )
    46. )
    47. --1) create biped
    48. --2) kies type (slider)
    49. --3) kies lengte (aka snelheid)
    50.  
    51.  
    52. CreateDialog WalkcycleCreator
    53. --addRollout WalkcycleCreator

    I want to make from 'tijd' a global variable so i can change the animationrange when you turn the spinner but it give's this error "** system exception **"
  • monster
    Offline / Send Message
    monster polycounter
    Inside the rollout definition you can't actually execute code. You can only define the UI and what happens when you interact with the UI.

    But, you can execute code once the rollout is created.

    on WalkcycleCreator open do
    (
    global tijd = TijdSpinner.value
    )
  • Sandeir
    thanks monster, that was the missing link i guess :D

    so here's my code up 'till now
    1. rollout WalkcycleCreator "WalkcycleCreator" width:224 height:272
    2. (
    3. spinner TijdSpinner "Timespinner" pos:[10,30] type: #integer width:200 height:44 range: [12, 36, 0]
    4. slider TypeSlider "small - normal - cartoony" pos:[20,100] type: #integer width:200 height:44 range: [0, 10, 5]
    5. button btnCreate "Create" pos:[20,180] width:100 height:50
    6. on WalkCycleCreator open do
    7. (
    8. global tijd = TijdSpinner.value
    9. global type = TypeSlider.value
    10. )
    11. on TijdSpinner changed value do
    12. (
    13. tijd = TijdSpinner.value
    14. animationrange.start = 0
    15. animationrange.end = tijd as time
    16. )
    17. on TypeSlider changed value do
    18. (
    19. type = TypeSlider.value
    20. print type
    21. )
    22. on btnCreate pressed do
    23. (
    24. framerate = 25
    25. --Create Biped---------------------------------------------------------------------
    26. Bip001 = biped.createNew 170 -90 [0, 0, 165] spineLinks: 2
    27. --------------------------------------------------------------------------------------
    28. animationrange = interval animationrange.start animationrange.end
    29. typeAnimatie = TypeSlider.value
    30. --tijd = TijdSpinner.value
    31. print tijd
    32. with animate on
    33. (
    34. --
    35. toolmode.coordsys #local
    36. slidertime = 0
    37. select $Bip001
    38. move $ [0, 0, -6]
    39. rotate $ (angleaxis 5 [0,1,0])
    40. rotate $ (angleaxis 20 [0,0,1])
    41. select $'Bip001 R Foot'
    42. move $ [10,-13,2]
    43. rotate $ (angleaxis -20 [0,0,1])
    44. rotate $ (angleaxis -5 [0,1,0])
    45. rotate $ (angleaxis -30 [1,0,0])
    46. biped.SetSlidingKey $'Bip001 R Foot'
    47. select $'Bip001 L Foot'
    48. move $ [0, 13, 2]
    49. rotate $ (angleaxis -20 [0,0,1])
    50. rotate $ (angleaxis 30 [1,0,0])
    51.  
    52. slidertime = (tijd/4) as time
    53. select $Bip001
    54. move $ [0, 0, 10]
    55. select $'Bip001 R Foot'
    56. move $ [0, 50, 0]
    57. biped.SetSlidingKey $'Bip001 R Foot'
    58. )
    59. )
    60.  
    61.  
    62. )
    63. --1) create biped
    64. --2) kies type (slider)
    65. --3) kies lengte (aka snelheid)
    66.  
    67.  
    68. CreateDialog WalkcycleCreator
    69. --addRollout WalkcycleCreator
  • Sandeir
    and also does someone has some great reference about scripting animation with a biped?
    found dees : http://www.cgplusplus.com/online-reference/maxscript-reference/source/biped_maxscript_extensions.htm
    but that's just the help
Sign In or Register to comment.