instantreality forum
news: Welcome to the instantreality forums!
Welcome, Guest. Please login or register.
Did you miss your activation email?
March 19, 2018, 05:52:16 am

Login with username, password and session length

Pages: [1]
Author Topic: Change or create script node via javascript  (Read 1898 times)
Posts: 5

View Profile
« on: August 03, 2013, 03:29:06 pm »


i want to generate an previous unknown number of functions to call through timesensors in a script node. The two possibilities i can think of at the moment are:

- generating a predefined script node with a function and to route to it
- add fields to an existing script nodes

However, both possibilites don't seem to work in X3D or i did not found the right way to do it. For the second way i am not able to find a function to add a field in the javascript API. For the first way i tried code which looks like this:

var uid = Math.random().toString(36).substr(2,9);
var script_node_def = "script_" + uid;
var scene_string =    '<X3D version="3.0">\n' +
'  <Scene>\n' +
'      <Script DEF="' + script_node_def + '">\n' +
'        <field name="foo" type="SFFloat" accessType="inputOnly" />\n' +
'      </Script>\n' +
'  </Scene>\n' +

var scene = Browser.createX3DFromString(scene_string);
var script_node = scene.getNamedNode(script_node_def);
var timesensor = Browser.currentScene.createNode('TimeSensor');
timesensor.loop = true;
timesensor.cycleInterval = 1;
Browser.currentScene.addRoute(timesensor, 'fraction_changed', script_node, 'foo');

But the only thing i get is "Cannot create ScriptEvaluator" and tons of messages stating that there is no script evaluator for the node.

Is there a way to achieve what i want to do?

Best regards

Posts: 16

View Profile
« Reply #1 on: March 06, 2014, 03:30:11 pm »

I also hatd problems with the addChiled methode, and also with the standard way new MFNode(my_new_node). Waht worked for me: you can extend an array in Java script with the [] operator

my_array[array.lenght] = my_new_node;

Looks ugly, but works.
Pages: [1]
Jump to:  

Powered by SMF 1.1.15 | SMF © 2011, Simple Machines