AI Service doesnt works correctly

Hello everybody!

I am starting in the world of AI and I am making simply AI bots. I have read that to make changes on the blackboard variables I need to use the Service node, so I create a service node every 0.5 seconds to get a random number and if that number is lower or equal to another, change a value.

The problem is that to debug the code, I print the boolean value of the lower or equal node and also I print when I change the value in the blackboard.

Like you see, I print the boolean value and then I use a branch. The idea is that when I print a true, then a wait need to be printed, but thats not true.

251699-foto2service.png

In the first example, a wait is printed but before that is there a false, not a true. And in the second one, I print a true but it doenst print a Wait.

Here is the behaviour tree and the service code of changeValue, that modify a value of a blackboard variable.

Thanks for your time!

Could you save (set) your random number in a local integer variable before using it in the compare and say if it’s working as intended?

My suspicion: Every time you get to an execution node, blueprint executes the whole pure tree until it produces the value the node needs. This means that the “Random Integer In Range” generates 2 different values - one for the “Print String” node and one for the “Branch” node.

Anyway, that’s a hunch so you should probably try it to be sure.

That is! Every time that I get the value gives me a different random, so I put the first value in a local variable and now it works! Thanks!