0

I'm building a desktop application using litegraph.js https://github.com/jagenjo/litegraph.js?files=1. What I need to do is to create new nodes to my graph dynamically. Following litegraph instructions, they can be defined by using a function like:

function my_new_node() {
    this.addInput("in1");
    //more constructor settings..
}

And then registering it to litegraph by:

LiteGraph.registerNodeType("basic/" + node_id + "", my_new_node);

My problem starts when I have to set different nodes dynamically added by the user, so I would like to do something like:

var node_id = node1; /* node1 is a string that user introduces with an input field, let's suppose this value to be node1. */

function node_id() { //But I want node_id to be node1 in runtime. 
    //constructor settings
}

LiteGraph.registerNodeType("basic/" + node_id + "", node_id);

I have already tried stuff like this[node_id] = () =>, but then it doesn't let me to register the node.

Any help will be appreciated. Thanks.

  • Why do you want them to have names at all? Just use an anonymous function: `.registerNodeType("basic/" + node_id, function() { ... })` – Andreas Mar 15 '21 at 15:23
  • @Andreas You are totally right. The answer is because I am amateur at programming and there is "basic" behavior I'm not conscious about. Thank you a lot! – Anton Villalonga Gomà Mar 15 '21 at 15:50

0 Answers0