Page 1 of 1
randomize radio switch select
Posted: 09 Mar 2012 16:45
by drewboles
Hey everybody -
I'm wondering if there is an easy way to randomize which of 16 radio-engaged switches gets selected. I basically have a bank of presets, and it would be nice to have a random button that randomizes which one gets chosen. Any recommendations? Thanks!
Drew
Re: randomize radio switch select
Posted: 04 Jun 2012 18:02
by blablub
I do have the exakt same question... anybody?
Re: randomize radio switch select
Posted: 04 Jun 2012 19:51
by bxsj
Attached is an example. Hope that helps.
BxSj
Edit: Attachment removed, see below.
Re: randomize radio switch select
Posted: 05 Jun 2012 07:00
by Macciza
Hi
Was going to post something - similar to yours but slightly more minimal . . .
Instead this provides an opportunity for comment on program design approachs.
There are many ways to achieve the same thing in programming - Lemur is no exception.
In bxsj's example there is a pad and a bank of radio-switches - the pad randomly selects a switch
In this case the Pad itself has the code to change the switch - I would call this a 'procedural' approach
if something else wants to change it you copy the code; to change something else you edit it etc . ..
Looking at them as 'objects' - it becomes a bit different - Let's focus on the Pad/Switches object relationship instead. . .
I am a Pad - I tell people my value when it is changed
I am a Switch - I know my value and I can change and display my values
So now we could take that same script out from the Pad and put it in the Switch as a rand_sel script.
If you set it to execute on Pads.x you have essentially the same situation as previously except local to the Switches.
Ofcourse now if you want some thing else to change it you have to add logical condition to the execution mode
The other option is to make the above script a manual script / function, instead of executing on Pads.x
Then add an action script to the Pad - that calls the Switches.rand_sel function.
This Switches.rand_sel function could then be called from anywhere very easily
Hope that makes some sense
MM
Re: randomize radio switch select
Posted: 08 Jun 2012 13:20
by bxsj
Hi Macciza,
I just read your post, point taken. My example is an example of bad design
At least I'd call it an convoluted shot from the hip
Here is the approach you described, which makes the example more elegant and comprehensive.
Humble and ashamed,
BxSj
Re: randomize radio switch select
Posted: 09 Jun 2012 11:47
by Macciza
Hi Bxsj
No worries, Not necessarily bad, or convoluted - just somewhat procedural in perspective . . .
And nothing really 'wrong' with it - if it works, it works (finer points of code efficiency put aside)
It just allowed a good example to show differing ways of approaching problems and putting together solutions for people new to coding . . .
Procedural is often very hands on and quick to get something ie the Pad randomises the Switches - pretty straight forward, code away . . .
But the 'object' thinking often takes that little while longer, and sometimes is not immediately visible as needed
When one brings re-usability into the equation the object approach really comes to the fore - ie getting other things to trigger the randomising script.
I think I had my random function under the Switches so you end up doing Switches.random sort of thing, but external is good to - I like the idea of a functions container here
I guess the next stage of refactoring as a global function might be to make a function that you could hand any object to, and say randomise this, and it would . . .
I guess looking up Object-Oriented vs Procedural Programming would help some people here,
Also Model View Controller approach might help conceptually - though there are several versions of this, I don't mind Apples view here
Basically a View takes User input and sends it to a Controller that updates the Model and notifies the Controller that then gets the View to update.
So nothing to be humbled or ashamed for, you should be proud of having provided a solution,
I'm glad you did, I had been quite busy of late and not on as much or had time to answer as many questions.
cheers
MM