Page 1 of 1

how to use setexpression with radiobuttons

Posted: 05 Feb 2013 14:51
by jbgeluid
hello,

I am trying to set a radiobutton to a certain state with another button, but it does not work.
what i tried:

1. to use a normal "button" to change the state of another button called CustomButton2, this script works;
"button" sets ' CustomButton2.x to "on" or to "1'..
script used in the "button":
setexpression(CustomButton2,' x', 1);

2. to convert this script so it will be usable for radioswitches, normaly you adress a radioswitch like this: 'x[0]' for the first button, 'x[1]' for the second button and so on.
so I expect the script for a radiobutton called "Switches" with 3 buttons ( 'x[0]', 'x[1]', and 'x[2]') to be;

setexpression(Switches, 'x[1]', 1);

to set the radioswitch to the "second button" so to speak.
this does not work..
I also tried:

decl ind=firstof(Switches.x);
setexpression(Switches, 'x[1]', 1);

and tried if adding the state of all the other buttons in the radiobutton would make a difference:
setexpression(Switches, 'x[0]', 0);
setexpression(Switches, 'x[1]', 1);
setexpression(Switches, 'x[2]', 0);

none of this works.
Odley enough the script:

setexpression(Switches, 'x', 1);

works, this sets ALL the radioswitches buttons to on (or off when you use '0' instead of '1').

Does anybody know what I am doing wrong here?

thanks,
Jurgen

Re: how to use setexpression with radiobuttons

Posted: 05 Feb 2013 16:38
by Softcore
Actually I have a question...

why not use

Code: Select all

Custombutton.x=0;
and go with the setexpression approach?

Consequently why not

Code: Select all

Switches.x[0]=1;
...Doesnt it work?

Re: how to use setexpression with radiobuttons

Posted: 05 Feb 2013 17:04
by jbgeluid
Yep, thanks..

I guess I was overcomplicating things, but I actualy found this previous way of scripting in the manual...

Your solution:

Code: Select all

Switches.x[0]=0;
Switches.x[1]=1;
Switches.x[2]=0;
works, this sets the switch to the middle position...

Thanks again, Jurgen

Re: how to use setexpression with radiobuttons

Posted: 05 Feb 2013 17:26
by Softcore
To this day I still havent found a use for 'setexpression' - I believe though it is to be used when the expression you want to set an object may be changed dynamically by scripting in the project....my stuff are up to now fairly simple so just setting the expressions like above works for me....I'd love to see an example however or a showcase where the 'setexpression' way is to be used and accomplishes something that cant be accomplished in other ways....