431

Writing program scripts with JavaScript
Building a color selector

  • The turns lamp on and off, but the light bulb doesn't change color!

  • A color selector script sends an on color on a TRUE input, and an off color on a FALSE input

    DEF ColorSelector Script {
        field    SFColor onColor  1.0 1.0 1.0
        field    SFColor offColor 0.0 0.0 0.0
        eventIn  SFBool  set_selection
        eventOut SFColor color_changed
        url "vrmlscript:
            function set_selection( b, ts ) {
                if ( b == TRUE )
                    color_changed = onColor;
                else
                    color_changed = offColor;
            }"
    }