I try to random integer but found it not working correctly. Here the example from fresh build. version 4.16.2
Well I was design for loot item drop and it one time used but I wanted to know the result after it finish.
Oh I see. I try again and it worked. That it need to assign variable to store and get variable. By linking direct to branch break checks. Thank you for helping out.
It’s working fine, but this is a common misunderstanding of how pure functions work in Blueprint.
There are two ways to execute functions in Blueprint
-
Pure functions (they do not have the white execution pins, in your example, RandomInteger)
-
“Normal”/Impure functions with execution pins.
When you execute a normal function, the return values will be cached and can be re-used and will stay the same value until the function is executed again via its execution pin.
Pure functions (GetActorLocation, RandomInteger, etc) are executed every time something “pulls” from its return value. You basically have to trace the execution backwards. In your example, the Branch node sees that it has to get a boolean value from the GreaterThan node its connected to. The GreaterThan node sees it needs an Integer value from the RandomInteger node its connected to, and so the RandomInteger node/function is executed.
What is happening in your example is that RandomInteger rolls the dice once because your Branch node is asking for a number from it, and then it rolls the dice again because your Print nodes are also pulling from it and so it gives your Print nodes a different value.
The solution is to save the RandomInteger as a variable, and then print that variable instead of connecting multiple things to the RandomInteger node.
Not sure if I fully understand, but just right click on the random integer pin and promote to variable. Then you check if it’s over 50 and use this variable to print the string.