Help with Arrays

Hello, guys!

I am trying to close the issue. Currently i am trying to increase the logic nodes functionality, but always based in already existent nodes. In this case, i don’t find any node similar to this. Arrays looks very confuse for a beginner (i never touched in any script since the last week).

I am trying to follow Armory API and this page (https://code.haxe.org/category/beginner/arrays.html) to clear some doubts.

The problem is that this part of the page show me a simple example of array usage, that is:

var strings:Array = [“Apple”, “Pear”, “Banana”];
trace(strings);

It works as i want (trace all content of the array) but don’t work for my purpose.

In Armory API there is a variable called children. The steps i do is:

Define the objectChildren variable:

var objectChildren: Array = object.children;

First problem: I trace the value of objectChildren. The value is confuse, but if i use trace(object);, i can see that both values are very similar. The problem is: if i try to set the visibility of the objectChildren, i got an error (something like: “objectChildren don’t have field children”) but when i set the object.visible it works fine (why if it is a similar value?)

Second problem: how do i get the entire content of an array and apply what i want (that is the object visibility)? Did i need to loop the array using its indexes or there is some direct method?

If someone could provide some example for me about this… because i don’t find nothing this specific around Haxe Foundation site. I also appreciate links.

You need to loop thought the array like this for example:

    for child in objectChildren{
         child.visible = flase;
    }
1 Like

Thanks for reply!

In this case:

switch (property0) {
case "Object":
object.visible = visible;

if (children == true) for child in objectChildren{
child.visible = visible;

I got "Unexpected child". How do i loop here? Is there some other node that i can use as example?

Edit: now it is working, i only miss the “(” for child in objectChildren “)”

Thank you very much! :+1:

1 Like

Could you post the full code, please

Here is the code:

package armory.logicnode;

import iron.object.Object;

class SetVisibleNode extends LogicNode {

        	public var property0: String;

    	public function new(tree: LogicTree) {
    		super(tree);
    	}

    	override function run(from: Int) {
    		var object: Object = inputs[1].get();
    		var visible: Bool = inputs[2].get();
    		var children: Bool = inputs[3].get();

    		if (object == null) return;

    		var objectChildren: Array<Object> = object.children;

    		switch (property0) {
    		case "Object":
    			object.visible = visible;
    			if (children == true) for (child in objectChildren) {
            	child.visible = visible;
            	}

    		case "Mesh":
    			object.visibleMesh = visible;
    			if (children == true) for (child in objectChildren) {
    			child.visibleMesh = visible;
    			}

    		case "Shadow":
    			object.visibleShadow = visible;
    			if (children == true) for (child in objectChildren) {
    			child.visibleShadow = visible;
    			}
    		}

    		runOutput(0);
    	}
    }

it is working fine, but if have some way to make it more optimized i can fix it before the pr

I think it is good!

You may make a PR

1 Like