How to set custom node ouput?


#1

After looking on some examples I still cant figure out how to pass data to outputs in my custom made node.

For instance I added successfully to my blender.py the

self.outputs.new('NodeSocketString', 'Data')

now I am looking forward to feed the ‘Data’ outlet of my node from my haxe class with a string variable I yield from my node (accomplished the http request part - Wrangling with external data).

unfortunately it stills not to be clear for me how to pass my data variable from node to node, I see the using of

retrun value;

syntax but how to define which outputs get what, it is very obscure. Any guidance will be appreciated !


#2

Returning on specific outputs is pretty weird. You need to use this function:

override function get(from:Int):Dynamic {
var x = 1;
var y = 2;
if (from == 0) {
		return x;
	}
else if (from == 1) {
		return y;
        }

with this function the node returns 1 on its first output-socket and 2 on its secound.


#3

hm by using this functions I get an error in compilation (or I should say a warning) since it compiles but in terminal says that something is going wrong with the python socket.

and one more, if I use get() instead of run() or I should both in my class ?

PS: so for each var I declare in the function I yield one output with the “return” ?


#4

run() is only running when the node’s red input is active, get() is always going (I think). You can return as often if the if (from==x) method as long as you have outputs declared in your node’s python defintion. (if x=0 this means the first output of your node)


#5

ah ok I see, so “from” is the magic component ! thank you @Simonrazer


#6

although I get this error :

Missing return: Dynamic (32,3)

  • 32,2 is the if (from==0) condition *

#7

oh I forgot, it is gonna complain if you don’t have an else statement. So you probably need to replace you the last else if (from == x){return y;} with just else{return y;}.

.


#8

yes-yes noticed that, so in order to keep things in tact, I use the get() instead of run(), and the “from” variable to target the according node outlet. Then I need an if-else condition and I am done. Right ?


#9

Yes, but I’d only but the stuff that is supposed to handle returning in the get()-method, if you want the node to be activatable. Else it is gonna run every frame, so that is maybe not what you want.


#10

hm true, so is there a way to do it in run() method ?


#11

you can simply have both in you class! The output will still be going, but whatever the main part of the node is about is stopped. To not let the next nodes run simply put super.run() at the end od the run() method, which activates the node’s red output, on which the next nodes do depend. So if this node is not doing run(), the next won’t either.


#12
package armory.logicnode;

import haxe.Http;


class HttpRequest extends LogicNode {
	var url:String;
	var DataOut:String;
	public function new(tree:LogicTree) {
		super(tree);
	}

	override function run() {
		// Logic for this node
		
		url = inputs[1].get();
		var req = new haxe.Http(url);
		req.onData = function(data){
			DataOut = data;
		}

		req.request();
		
		// Execute next action linked to this node
		super.run();
		
		
	}

	override function get(from:Int):Dynamic {
		if(from==0){
			return DataOut;
		}
		else
		{

			return DataOut;
		}
		

	}

}

This is my code, but when I compile the DataOut is null, is it the way I am refering to Class variable or the http request itself is messing the things ?


#13

is DataOut still null if you print it? (=trace(DataOut); ) Then something is probably wrong with the http stuff. Also if you only need to output one variable and you node also has just one variable output you can simply use return X; in the get()method. https://github.com/armory3d/armory/blob/master/Sources/armory/logicnode/GetVisibleNode.hx


#14

ok I think that I found the proper way to do so, I had to put runOutputs(x) in my else if statements in run() method. Now it works pretty well !

Like so :

class HttpRequest extends LogicNode {
	var url:String;
	var dataOut:String;
	var status:Int;
	public function new(tree:LogicTree) {
		super(tree);
	}

	override function run() {
		// Logic for this node
		
		url = inputs[1].get();
		var req = new haxe.Http(url);
		req.onData = function(data){
			this.dataOut = data;
			runOutputs(0);
		}
		req.onStatus= function(stat){
			status = stat;
			runOutputs(1);
		}
		

		req.request();
		
		// Execute next action linked to this node
		super.run();
		
		
	}

	override function get(from:Int):Dynamic {
		if(from==0){
			return this.dataOut;
		}
		else if(from==1){
			return this.status;
		}
		else{
			return this.dataOut;
		}
		
		

	}

}