[Closed] Spinner question
Hi everybody
I have a spinner which control teapot position and a button when it got pressed change the value of the spinner .
Now my problem is when the button changes the snipper’s value why the position of teapot doesn’t change ?
rollout unnamedRollout "Untitled" width:162 height:200
(
spinner 'sld1' "Slider" pos:[2,15] width:136 height:44 range:[-100,100,0] align:#left
button 'btn1' "Button" pos:[30,84] width:78 height:61 align:#left --visible:off
on sld1 changed val do
(
$Teapot001.pos.x = val
)
on btn1 pressed do
(
sld1.value = 50
)
)
CreateDialog unnamedRollout
Thanks in advance
In max, that’s just how it is, you’d have to call the changed handler yourself (here it could be for example sld1.changed sld1.value).
here’s my logic…apologies if it appears as if I’m regurgitating what Swordslayer is already saying…
you control the pos of the Teapot by saying $Teapot001.pos.x = blahblah, fine and good, all works in on sld1 changed val.
Now on btn1 pressed all you’ve done is changed the value of the SPINNER, you haven’t done anything to the Teapot.
Think the other way, if you take out the statement $Teapot001.pos.x = val in on sld1 changed val, then nothing works because you can update the spinner all day long but you’re not doing anything to the pos of the Teapot.
So logic is simple, you update the spinner value to 50, THEN, you must also update the pos of the Teapot.
So new code is: (just a 1 liner at the bottom)
rollout unnamedRollout "Untitled" width:162 height:200
(
spinner 'sld1' "Slider" pos:[2,15] width:136 height:44 range:[-100,100,0] align:#left
button 'btn1' "Button" pos:[30,84] width:78 height:61 align:#left --visible:off
on sld1 changed val do
(
$Teapot001.pos.x = val
)
on btn1 pressed do
(
sld1.value = 50
$Teapot001.pos.x = sld1.value -- update pos with value
)
)
CreateDialog unnamedRollout
Thanks to both of you for your answer and participation
vusta thanks for the code but i didn’t want to repeat the main code which here is —-$Teapot001.pos.x …—-
in the button section .
I think Swordslayer try to say this
rollout unnamedRollout "Untitled" width:162 height:200
(
spinner 'sld1' "Slider" pos:[2,15] width:136 height:44 range:[-100,100,0] align:#left
button 'btn1' "Button" pos:[30,84] width:78 height:61 align:#left --visible:off
on sld1 changed val do
(
$Teapot001.pos.x = val
)
on btn1 pressed do
(
val = 50
sld1.changed val
sld1.value =50
)
)
CreateDialog unnamedRollout
Thank for your answers
well, told ya I’m a non scripter but now that that I see the logic…I think what Swordslayer meant was this
on btn1 pressed do
(
sld1.value = 50
sld1.changed sld1.value
)
on sld1 changed val do
(
$Teapot001.pos.x += val -- if you want to change the pos of the teapot with slider
)
on btn1 pressed do
(
local vals= 50
sld1.value = vals -- or (+= vals ) to increment already assigned value each time you press the bton, like 50, 100,150,...etc
$Teapot001.pos.x += vals -- could be subtitute with sld1.value
-- if you want to change the pos of the teapot with button pressed
)