danni.coy Posted July 28, 2011 Share Posted July 28, 2011 What is the correct way to do this so that the nodes are removed when the script exits i.e. world reload ? Link to comment
manguste Posted August 3, 2011 Share Posted August 3, 2011 Sorry, can't provide you with any useful info here as our developers did not give it a go. Link to comment
ulf.schroeter Posted August 3, 2011 Share Posted August 3, 2011 What is the correct way to do this so that the nodes are removed when the script exits i.e. world reload ? I am not sure if it's a good design pattern to add nodes from within WorldExpression. Doing this in world script init() and removal in shutdown() seems to be much more 'natural'. What would be a good use case for such an approach ? Link to comment
danni.coy Posted August 4, 2011 Author Share Posted August 4, 2011 I am not sure if it's a good design pattern to add nodes from within WorldExpression. Doing this in world script init() and removal in shutdown() seems to be much more 'natural'. What would be a good use case for such an approach ? Mostly I am figuring out what is possible using a WorldEpression and a Property. I am using one of the properties states to reinitialize the WorldExpression. Using this approach I can prototype code much faster (I don't have to restart the world to make changes to the specific piece of code I am working on ). When I am working directly in one of our jobs reload time can be over a minute - due to size of material libraries, size of world and number of assets. It also puts code in small enough chunks that our artists are perhaps willing to play with it. The specific thing I am trying is a procedural escalator. The WorldExpression is trying to calculate the number steps the esculator needs based on the length of the esculator (represented by a list of dummy nodes). These steps should be generated as the artist moves the controls (which I can do using the objects property). I can add the generated nodes to the editor script but this means adding a whole bunch of nodes to the editor that the artists don't need to see and shouldn't manipulate directly. I can do this in other ways I am just trying to figure out what is possible and If I can get it working I can see some quite powerful things that can be done with it. psuedocode looks something like this { enum {RESET_NODE=0,}; Node node = getNode(); Property property = node.getProperty(); if(property == 0 || property.getName()!= "propertyname") {return;} if (property.getState(RESET_NODE)) { property.setState(RESET_NODE,0); // calculate needed number of dynamically generated nodes // remove/add nodes as needed *NEED HELP WITH THIS BIT* // make node parent a known node to be able to access them } // move generated nodes to required positions } Link to comment
manguste Posted August 4, 2011 Share Posted August 4, 2011 Creating nodes is not a problem as long as you delete them and clear the array in the end. It's the same rule that applies to WorldExpression code just like for any other script. It can be something like this: // constants int ACTION_TYPE = 0 // index of the state enum { ACTION_TYPE_NODE = 0 ACTION_TYPE_RELOAD, ACTION_TYPE_DELETE, }; // fields Node nodes[0]; // if declared upon initialization, this field will not be cleared between WorldExpression calls // helper functions void delete_nodes() { nodes.delete(); nodes.clear(); } void load_nodes() { Node node = new Node(); .... nodes.append(node); } // main { Node node = getNode(); Property property = node.getProperty(); if(property == 0 || property.getName()!= "propertyname") {return;} switch(property.getState(ACTION_TYPE)) { case ACTION_TYPE_DELETE: delete_nodes(); break; case ACTION_TYPE_RELOAD: delete_nodes(); load_nodes(); break; } property.setState(ACTION_TYPE,ACTION_TYPE_NODE); ... } Link to comment
danni.coy Posted August 4, 2011 Author Share Posted August 4, 2011 Thankyou very much - That example showed me so much about WorldExpressions I had no idea were possible. Link to comment
Recommended Posts