Home Technical Talk

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.
    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
    rollout WalkcycleCreator "WalkcycleCreator" width:224 height:272
    (
    	spinner TijdSpinner "Timespinner" pos:[10,30] type: #integer width:200 height:44 range: [12, 36, 0]
    	slider TypeSlider "small - normal - cartoony" pos:[20,100] width:200 height:44
    	button btnCreate "Create" pos:[20,180] width:100 height:50
    	
    	
    	on btnCreate pressed do
    	(
    		framerate = 25
    		--Create Biped---------------------------------------------------------------------
    		Bip001 = biped.createNew 170  -90 [0, 0, 165] spineLinks: 2
    		--------------------------------------------------------------------------------------
    		
    		typeAnimatie = TypeSlider.value
    		print typeAnimatie
    		lengteAnimatie = TijdSpinner.value
    		print lengteAnimatie
    		
    		--tijd = TijdSpinner.value
    		tijd = ( TijdSpinner.value as time )
    		print tijd
    		animationRange = interval 0 12
    		with animate on 
    		(
    			toolmode.coordsys #local
    			slidertime = 0f
    			select $Bip001
    			move $ [0, 0, -20]
    			rotate $ (angleaxis 5 [0,1,0])
    			rotate $ (angleaxis 20 [0,0,1])
    			select $'Bip001 R Foot'
    			--move $ [0, -30, 10]
    			move $ [10,-40,10]
    			rotate $ (angleaxis -20 [0,0,1])
    			rotate $ (angleaxis -5 [0,1,0])
    			rotate $ (angleaxis -30 [1,0,0])
    			
    			biped.SetSlidingKey $'Bip001 R Foot'
    
    			slidertime = (tijd/2)f
    			select $Bip001
    			move $ [0, 0, 10]
    			select $'Bip001 R Foot'
    			move $ [0, 50, 0]
    			biped.SetSlidingKey $'Bip001 R Foot'
    		)
    		
    	) 
    	
    	
    		
    )
    --1) create biped
    --2) kies type (slider)
    --3) kies lengte (aka snelheid)
    
    
    CreateDialog WalkcycleCreator 
    --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
    tijd = TijdSpinner.value
    		animationRange = interval 0 12
    		with animate on 
    		(
    			
    			toolmode.coordsys #local
    			slidertime = 0
    			select $Bip001
    			move $ [0, 0, -20]
    			rotate $ (angleaxis 5 [0,1,0])
    			rotate $ (angleaxis 20 [0,0,1])
    			select $'Bip001 R Foot'
    			--move $ [0, -30, 10]
    			move $ [10,-40,10]
    			rotate $ (angleaxis -20 [0,0,1])
    			rotate $ (angleaxis -5 [0,1,0])
    			rotate $ (angleaxis -30 [1,0,0])
    			
    			biped.SetSlidingKey $'Bip001 R Foot'
    
    			slidertime = (tijd/2) as time
    			select $Bip001
    			move $ [0, 0, 10]
    			select $'Bip001 R Foot'
    			move $ [0, 50, 0]
    			biped.SetSlidingKey $'Bip001 R Foot'
    		)
    

    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:
    rollout WalkcycleCreator "WalkcycleCreator" width:224 height:272
    (
    	spinner TijdSpinner "Timespinner" pos:[10,30] type: #integer width:200 height:44 range: [12, 36, 12]
    	slider TypeSlider "small - normal - cartoony" pos:[20,100] width:200 height:44
    	button btnCreate "Create" pos:[20,180] width:100 height:50
    	
    	
    	global tijd = TijdSpinner.value
    	
    	on TijdSpinner changed value do
    	(
    		animationrange.start = 0
    		animationrange.end = tijd as time
    	)
    	on btnCreate pressed do
    	(
    	framerate = 25
    	--Create Biped---------------------------------------------------------------------
    	Bip001 = biped.createNew 170  -90 [0, 0, 165] spineLinks: 2
    	--------------------------------------------------------------------------------------
    		
    		typeAnimatie = TypeSlider.value
    		--tijd = TijdSpinner.value
    		print tijd
    		with animate on 
    		(
    			--
    			toolmode.coordsys #local
    			slidertime = 0
    			select $Bip001
    			move $ [0, 0, -20]
    			rotate $ (angleaxis 5 [0,1,0])
    			rotate $ (angleaxis 20 [0,0,1])
    			select $'Bip001 R Foot'
    			--move $ [0, -30, 10]
    			move $ [10,-40,10]
    			rotate $ (angleaxis -20 [0,0,1])
    			rotate $ (angleaxis -5 [0,1,0])
    			rotate $ (angleaxis -30 [1,0,0])
    			
    			biped.SetSlidingKey $'Bip001 R Foot'
    
    			slidertime = (tijd/2) as time
    			select $Bip001
    			move $ [0, 0, 10]
    			select $'Bip001 R Foot'
    			move $ [0, 50, 0]
    			biped.SetSlidingKey $'Bip001 R Foot'
    		)
    		
    	) 
    	
    	
    		
    )
    --1) create biped
    --2) kies type (slider)
    --3) kies lengte (aka snelheid)
    
    
    CreateDialog WalkcycleCreator 
    --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
    rollout WalkcycleCreator "WalkcycleCreator" width:224 height:272
    (
    	spinner TijdSpinner "Timespinner" pos:[10,30] type: #integer width:200 height:44 range: [12, 36, 0]
    	slider TypeSlider "small - normal - cartoony" pos:[20,100] type: #integer width:200 height:44 range: [0, 10, 5]
    	button btnCreate "Create" pos:[20,180] width:100 height:50
    	
    	on WalkCycleCreator open do
    	(
    		global tijd = TijdSpinner.value
    		global type = TypeSlider.value
    	)
    		on TijdSpinner changed value do
    		(
    		tijd = TijdSpinner.value
    		animationrange.start = 0
    		animationrange.end = tijd as time
    		)
    		on TypeSlider changed value do
    		(
    			type = TypeSlider.value	
    			print type
    		)
    	on btnCreate pressed do
    	(
    		framerate = 25
    		--Create Biped---------------------------------------------------------------------
    		Bip001 = biped.createNew 170  -90 [0, 0, 165] spineLinks: 2
    		--------------------------------------------------------------------------------------
    		animationrange = interval animationrange.start animationrange.end
    		typeAnimatie = TypeSlider.value
    		--tijd = TijdSpinner.value
    		print tijd
    		with animate on 
    		(
    			--
    			toolmode.coordsys #local
    			slidertime = 0
    			select $Bip001
    			move $ [0, 0, -6]
    			rotate $ (angleaxis 5 [0,1,0])
    			rotate $ (angleaxis 20 [0,0,1])
    			select $'Bip001 R Foot'
    			
    			move $ [10,-13,2]
    			rotate $ (angleaxis -20 [0,0,1])
    			rotate $ (angleaxis -5 [0,1,0])
    			rotate $ (angleaxis -30 [1,0,0])
    			biped.SetSlidingKey $'Bip001 R Foot'
    			select $'Bip001 L Foot'
    			move $ [0, 13, 2]
    			rotate $ (angleaxis -20 [0,0,1])
    			rotate $ (angleaxis 30 [1,0,0])
    
    			slidertime = (tijd/4) as time
    			select $Bip001
    			move $ [0, 0, 10]
    			select $'Bip001 R Foot'
    			move $ [0, 50, 0]
    			biped.SetSlidingKey $'Bip001 R Foot'
    			
    			
    			
    		)
    		
    	) 
    	
    
    
    )
    --1) create biped
    --2) kies type (slider)
    --3) kies lengte (aka snelheid)
    
    
    CreateDialog WalkcycleCreator 
    --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.