Notifications
Clear all

[Closed] Slider question

Hello maxscript masters,
Is there a way to avoid slider skipping values ?
Example simplified code:


 rollout slide ""
 (
 slider slide "Slider" range:[0,100,0] type:#integer 
 on slide changed val do print val
 )
 createdialog slide
 

If you move the slider from 0 to 100 super fast it skips most of the values.
I’m trying to make a script that makes sort of a ‘switch’ on a specific slider value. If I move it super slow it works, but if I move fast it completely ignores my “if” expression.
Any ideas?
Thank you in advance for your time.
Regards

3 Replies
 rollout slide ""
  (
 	slider slide "Slider" range:[0,100,0] type:#integer
 	
 	local lastval = 0
 	on slide changed val do
 	(
 		step = if (val > lastval) then 1 else -1
 		for k = lastval to val by step do print k
 		lastval = amin (amax 0 (val + step)) 100
 	)
  )
  createdialog slide

Absolutely brilliant! Thank you very very much denisT !!!

Hello again.
I’m bringing this topic back. I though for a long time that my script is working correct, but … surprise it doesn’t


 rollout slide ""
   (
 	 slider slide "Slider" range:[0,100,30] type:#integer
 	 
 	local lastval = 30.0
 	local defBig = 70.0
 	local defSmall = 30.0
 	local range=100.0
 
 	 on slide changed val do
 	 (
 		 step = if (val > lastval) then 1 else -1
 		 for k = lastval to val by step do (
 		print k -- debug
 		print step --debug
 			if k >= 30 then (
 			morphCurrent=WM3_MC_GetValue$base_Legs.morpher 2
 			morphCurrent=morphCurrent+(range/defBig)*step
 			WM3_MC_SetValue$base_Legs.morpher 2 morphCurrent
 			)
 			if k <= 30 then (
 			morphCurrent=WM3_MC_GetValue$base_Legs.morpher 6
 			morphCurrent=morphCurrent+(range/defSmall)*step
 			WM3_MC_SetValue$base_Legs.morpher 6 morphCurrent
 			)
 		)
 		 lastval = amin (amax 0 (val + step)) 100
 	 
   )
   )
 createdialog slide
 

What this portion of the script is suppose to do:
A slider that controls 2 different morph channels. Above 30 – channel 2 , below 30 – channel 6.

The full script control multiple bone sizes and positions, and more morph channels.
I’m aware that in this case I can set the morph value by using the “k” variable directly.
Something like this I suppose:

morphCurrent=(30.0 - k) * (100.0 / 30.0) as float

But I want to do it step by step in а cumulative way if it’s possible. The problem is that “step” variable jumps around: 1, -1 , 1 ,1 , -1 even if I push the slider in a single direction, so using it as step doesn’t give me a precise result at all.
Thank you very much in advance for you time!
Regards