Getting the returned value from a function inside a task

I’m using a custom NPC. I wanted to make some footsteps sfx while my NPC was walking, so I made this code:

var NavRes : navigation_result = navigation_result.Reached
Task := spawn{NPCNav.NavigateTo(NavTarget, ?MovementType := movement_types.Running, ?ReachRadius := 120.0)}
spawn{LoopFootSteps()}
Task.Await()
set NavRes = navigation_result[Task]

Basically I make the npc walk towards the target and play a loop of the footstep sfx until he reaches the target, using Task.Await().

But since I need to do certain things following certain situations, I need to access the value returned by Task := spawn{NPCNav.NavigateTo(NavTarget, ?MovementType := movement_types.Running, ?ReachRadius := 120.0)}, which is a navigation_result value.

My problem is that I don’t know how to access the navigation_result returned by this function.
Task is a variable of type task(navigation_result) but how do I access that navigation_result value?

I’ve tried on the last row (set NavRes = navigation_result[Task]), but it doesn’t work.

Help would be appreciated

That’s very simple! just like you got the task on a variable, you can get the task result in another variable:

MyTask()<suspends>:string = {
    Sleep(10.0)
    "Apples!"
}
#####
Task := spawn { MyTask() }
TaskResult := Task.Await()
Print("Result is: {TaskResult}")
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.