instantreality forum
news: Welcome to the instantreality forums!
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
January 17, 2018, 02:31:18 am


Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Change or create script node via javascript  (Read 1789 times)
jasch
Newbie
*
Posts: 5


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

Hello,

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:

Code:
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' +
'</X3D>\n';


var scene = Browser.createX3DFromString(scene_string);
var script_node = scene.getNamedNode(script_node_def);
Browser.println(script_node);
Browser.currentScene.refNode.addChild(script_node);
var timesensor = Browser.currentScene.createNode('TimeSensor');
timesensor.loop = true;
timesensor.cycleInterval = 1;
Browser.currentScene.refNode.addChild(timesensor);
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

Jan
Logged
Pellaeon
Newbie
*
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.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.15 | SMF © 2011, Simple Machines