Page 1 of 1

modules help, using values from sliders

Posted: Wed Nov 09, 2005 6:27 pm
by freakowen
Please bear in mind that I've never done any programming of any sort - so assume I know nothing :)

I've been playing around with the module creator, and I've figured out how to send different fixed values to a parameter when a button is pressed using up/down to(parameter) value=number in the keyword connect section.

So I've got it doing one thing when I press the button resetting to zero when the button is released.

What I can't figure out is how to use a slider to generate the number I'm sending. I'm attempting to get it to send the the value of the slider to(parameter) when the button is pressed and then reset to zero when the button is released.

Any really simple hints/tips or useful resources would be great :)

thanks in advance

Re: modules help, using values from sliders

Posted: Wed Nov 09, 2005 8:28 pm
by yves@garagecube
When the value of a control (like a slider) is changed a message is sent to the "messageEvent" script.

You receive two valiables:

- 'msg': The name of the message associated to the control. You define it in the interface builder in the "script connect" tab.

- 'param': The parameters of the message. It is a dictionary that contains information about the control. Its content depends of the control type.


The best way to know what is sent is simply to print it (if you don't want to read the doc ;-)).

So simply write in your messageEvent script:

print msg,param

Create a slider, set the message value as "sliderChanged" (in the script connect tab) and launch your module. Then open the script output window and change the value of the slider.

You will see in the output window:

sliderChanged {'NAME': 'Untitled', 'value': 0.45714285969734192}

As you can see the message is sliderChanged.
The second part is the parameters dictionary. NAME is for the name of the control (I did not set name, so it is 'Untitled'. 'value is the interesting part. It represents the new value of the slider.

So to get the value you simply have to extract it from the dictionary.

Typically your script can be:

Code: Select all

if msg=='sliderChanged':      # Is it the correct message ?
        v = param['value']             # Yes, I extract the new value


Now you have the value of the slider in v, ready to be used !

Hope this help!

Yves.

Re: modules help, using values from sliders

Posted: Wed Nov 09, 2005 8:37 pm
by yves@garagecube
Ok Part II:

The precedent post showed you how to handle value changes from a control.

Now, if you want to do the inverse (set the current value of the control), you should use the "module.setValue" function:

module.setValue(controlName,index,value)

- controlName : It is the name of the control (it is not the same as the script message!).
- index: It is only for control which may handle several values (like a X/Y pad). For a slider simply pass 0.
- value: The value.

For instance:

module.setValue('mySlider',0,0.5) # Set the control called 'mySlider' to 50%

You can also use the module.getValue to get the value of a control:

v = module.getValue('mySlider',0) # Get value of the control called 'mySlider'

Yves.

Posted: Wed Nov 09, 2005 9:07 pm
by freakowen
so if I put this:

print msg,param

if msg=='sliderChanged':
v = param['value']

if msg=='buttonPressed':
modul8.setValue(ctrl_master_addColorB,v)


I get the message in the script output telling me what the new value of the slider is and it gives me a message telling me if the button is pressed or not as 1 or 0.

I think I'm missing something; why does it not change the output blue level to the value of the slider when the button is pressed?

I did read the manual, but that was just as confusing :oops:

told you I didn't know anything about this lol

Posted: Thu Nov 10, 2005 2:23 pm
by yves@garagecube
If you simply put this:

print msg,param

You will see the result of any controls change (as long as you asssociated a message to them in "Script Connect tab).

Yves.

Posted: Thu Nov 10, 2005 3:24 pm
by freakowen
Hi Yves, I really appreciate you helping like this - I know you guys are really busy....but I wasn't joking when I said I didn't know anything about this - imagine you are explaining it to a child....

First I created a module with three buttons:

Image

On map 1 I put output blue, gave it a figure for down in the value and gave it 0 for up, I put red on map 2 and green on map 3. So when the button is pressed the three output colours change to the values I've specified and when the button is released it goes back to normal. I gave each of the buttons different values so pressing each button gives a different output colour:

Image

Then I thought it would be more useful if you could change the value using a slider before you press the button so I put three sliders in for each button:

Image

what I want it to do is set the value on each of the sliders, then when the button is pressed it send each slider value to the corresponding output colour bar and when the button is released the output colour goes back to normal but the slider values stay where they are - giving adjustable quick access presets.

I tired putting names in the script connect section for the sliders and using the print msg.param thing and it told me the value that the slider was changing to. Then I put in the section you indicated:

if msg=='sliderChanged': # Is it the correct message ?
v = param['value'] # Yes, I extract the new value

and then tried putting v in the value section for the button but this didn't do anything?

Image

Sorry for writing so much, but I think I might be asking the wrong questions so I thought it best if I put as much as possible information in. This is the first time I've tried anything like this and I thought this might be something simple which would help me understand it, but I'm just getting more and more confused - I might have to just leave the modules to people who know what they are doing :(