private void RunScript(InteractiveObject interactiveObject, String functionName, Object[] parameters) {
        boolean complete = false;
        if ( V8JavaScriptEngine) {
            GVRJavascriptV8File gvrJavascriptV8File = interactiveObject.getScriptObject().getGVRJavascriptV8File();
            String paramString = "var params =[";
            for (int i = 0; i < parameters.length; i++ ) {
                paramString += (parameters[i] + ", ");
            }
            paramString = paramString.substring(0, (paramString.length()-2)) + "];";

            final GVRJavascriptV8File gvrJavascriptV8FileFinal = gvrJavascriptV8File;
            final InteractiveObject interactiveObjectFinal = interactiveObject;
            final String functionNameFinal = functionName;
            final Object[] parametersFinal = parameters;
            final String paramStringFinal = paramString;
            gvrContext.runOnGlThread(new Runnable() {
                @Override
                public void run() {
                    RunScriptThread (gvrJavascriptV8FileFinal, interactiveObjectFinal, functionNameFinal, parametersFinal, paramStringFinal);
                }
            });
        }  // end V8JavaScriptEngine
        else {
            // Mozilla Rhino engine
            GVRJavascriptScriptFile gvrJavascriptFile = interactiveObject.getScriptObject().getGVRJavascriptScriptFile();

            complete = gvrJavascriptFile.invokeFunction(functionName, parameters);
            if (complete) {
                // The JavaScript (JS) ran.  Now get the return
                // values (saved as X3D data types such as SFColor)
                //  stored in 'localBindings'.
                //  Then call SetResultsFromScript() to set the GearVR values
                Bindings localBindings = gvrJavascriptFile.getLocalBindings();
                SetResultsFromScript(interactiveObject, localBindings);
            } else {
                Log.e(TAG, "Error in SCRIPT node '" +  interactiveObject.getScriptObject().getName() +
                        "' running Rhino Engine JavaScript function '" + functionName + "'");
            }
        }
    }
private void RunScript ( InteractiveObject interactiveObject , String functionName , Object [ ] parameters ) { boolean complete = false ; if ( V8JavaScriptEngine ) { GVRJavascriptV8File gvrJavascriptV8File = interactiveObject . getScriptObject ( ) . getGVRJavascriptV8File ( ) ; String paramString = "var params =[" ; for ( int i = 0 ; i < parameters . length ; i ++ ) { paramString += ( parameters [ i ] + ", " ) ; } paramString = paramString . substring ( 0 , ( paramString . length ( ) - 2 ) ) + "];" ; final GVRJavascriptV8File gvrJavascriptV8FileFinal = gvrJavascriptV8File ; final InteractiveObject interactiveObjectFinal = interactiveObject ; final String functionNameFinal = functionName ; final Object [ ] parametersFinal = parameters ; final String paramStringFinal = paramString ; gvrContext . runOnGlThread ( new Runnable ( ) { @ Override public void run ( ) { RunScriptThread ( gvrJavascriptV8FileFinal , interactiveObjectFinal , functionNameFinal , parametersFinal , paramStringFinal ) ; } } ) ; } else { GVRJavascriptScriptFile gvrJavascriptFile = interactiveObject . getScriptObject ( ) . getGVRJavascriptScriptFile ( ) ; complete = gvrJavascriptFile . invokeFunction ( functionName , parameters ) ; if ( complete ) { Bindings localBindings = gvrJavascriptFile . getLocalBindings ( ) ; SetResultsFromScript ( interactiveObject , localBindings ) ; } else { Log . e ( TAG , "Error in SCRIPT node '" + interactiveObject . getScriptObject ( ) . getName ( ) + "' running Rhino Engine JavaScript function '" + functionName + "'" ) ; } } }
Run the JavaScript program, Output saved in localBindings