To have a function that uses a return value, first we need to tell the code what type of variable it's going to return.
If we still have
DoSomething
in ourAwesomeEnemySpawner
class, delete that function. We'll make a new one calledCanHasCheeseburger
with a Boolean for a return value:function bool CanHasCheeseburger() { return true; }
The return type is declared after
function
and before the function name.Now let's call our function from
PostBeginPlay
. There are two different ways we can use the function. The first would be to create a variable and let the function assign a value to it:function PostBeginPlay() { local bool bCheeseburger; super.PostBeginPlay(); bCheeseburger = CanHasCheeseburger(); `log(bCheeseburger); }
This will give
bCheeseburger
whatever value the function returns us.Compile the code and test:
[0004.86] ScriptLog: True
The second way to use it would be to use the function itself as the variable. Since...