[solved] Problem with Timer Node

Hi,

I have the following setup:
setup
timer_scale.blend (663.7 KB)

It works as expected when executing the first time: I press space bar, my object is scaled down and after 1s it’s scaled back to its original size.

However, when pressing space bar a second time, the object will be scaled down and immediately be scaled back to its original size. The timer does not seem to run a second time, it seems that it still has it’s status of “done”.

Is this by design or a bug?

I suspect it’s a bug. I’m no coder at all, but I took a quick look at the source for the timer node:

package armory.logicnode;

class TimerNode extends LogicNode {

	var time = 0.0;
	var duration = 0.0;
	var repeat = 0;
	var running = false;
	var repetitions = 0;

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

	function update() {
		time += iron.system.Time.delta;
		if (time >= duration) {
			repeat--;
			runOutput(0);
			if (repeat != 0) {
				time = 0;
				repetitions++;
			}
			else {
				removeUpdate();
				runOutput(1);
			}
		}
	}
	
	override function run(from:Int) {
		if (from == 0) { // Start
			duration = inputs[3].get();
			repeat = inputs[4].get();
			if (!running) {
				running = true;
				tree.notifyOnUpdate(update);
			}
		}
		else if (from == 1) { // Pause
			removeUpdate();
		}
		else { // Stop
			removeUpdate();
			time = 0;
			repetitions = 0;
		}
	}

	inline function removeUpdate() { if (running) { running = false; tree.removeUpdate(update); } }

	override function get(from:Int):Dynamic {
		if (from == 1) return running;
		else if (from == 2) return time;
		else if (from == 3) return duration - time;
		else if (from == 4) return time / duration;
		else return repetitions;
	}
}

…and I noticed that “repetitions” is increased each time time is more than duration, but I don’t see anywhere that stops and resets the node if repetitions is greater or equal to the number set for repeat. This seems to make “Done” fire constantly, constantly keeping the cube at it’s 1.0 scale.

Anyway, I’ve filed a bug at:

@zicklag - What do you think?

1 Like

It looks like the latest Timer node on GitHub is different and has a bit more logic in it:

Try updating the logic pack and seeing if that fixes it. I think you were going in the right direction with your observation, though @Armored_Blob. :slight_smile:

Edit: Whoa never-mind. I thought that that the timer node was from the logic pack. I didn’t know Armory came with one like that. Maybe install the logic pack and see if the Timer node from that works, and if it does maybe we should merge it with the one in Armory core.

This just got fixed:

2 Likes