There is an optional argument for rb << set() to run the script besides selecting the button.
rb2 << set( 2, run script( 1 ) );
The script will only run if the button is not already selected, i.e. only the first time unless RB 4 is deselected. PMroz code forces the script to run every time RB 2 is selected/clicked. Compare his code with the below:
nw = New Window( "Radio Button Demo",
H List Box(
Panel Box( "Group 1",
rb1 = Radio Box(
{"RB 1", "RB 2"},
one_rb = rb1 << get selected;
If(
one_rb == "RB 1",
// then
Print( "Running RB 1 Code" ),
// else
one_rb == "RB 2",
Print( "Running RB 2 Code" );
rb2 << set( 2, run script( 1 ) );
))),
Panel Box( "Group 1",
rb2 = Radio Box(
{"RB 3", "RB 4"},
one_rb = rb2 << get selected;
If(
one_rb == "RB 3",
// then
Print( "Running RB 3 Code" ),
// else
one_rb == "RB 4", Print( "Running RB 4 Code" )
)))));