Array Node must be cleared before reusing it

discussion
#1

There seems to be a problem when reusing the node Array within the same node tree… , i.e. you have to associate a kind of Array Clear node with it before reusing it in the same node tree to be sure to have an empty Array.
(Thus I use a simple clear node whose code is as follows until a correction of the Array node is applied. This could also be useful for you too.
package armory.logicnode;
image

class ArrayClearNode extends LogicNode {
	var ar:Array<Dynamic>;
	public function new(tree:LogicTree) {
		super(tree);
	}

	override function run(from:Int) {
		ar = inputs[1].get();
	
		while (ar.length > 0){
    		ar.pop();
		}
		runOutput(0);
		
	}		
}
0 Likes

#2

What is the exact problem when you do not use “Array Clear”? I do not see any problem, the Array node should save its content so one process can do one thing with the data, another another thing. I assume by reusing the node you mean exactly the same node on the canvas.

0 Likes

#3

Yes, it’s when reusing **, I think it’s could be by default with a cleared Array otherwise we could have an input on the node in order to be sure to reinit the Array if needed … or not :wink: ***

** for example when you call several time a tree node using an On Event
*** need to stay prudent when using a Set Property with the Array Node being cleared … to be or not to be a reference / pointer

0 Likes