# Calling functions

**URL:** <https://forums.unrealengine.com/t/calling-functions/1586921>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [January 4, 2024, 8:25am UTC](https://forums.unrealengine.com/t/calling-functions/1586921 "2024-01-04T08:25:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgeri04](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@pgeri04](https://forums.unrealengine.com/u/pgeri04)\
**Post date:** [January 4, 2024, 8:25am UTC](https://forums.unrealengine.com/t/calling-functions/1586921/1 "2024-01-04T08:25:12Z")

</div>

Hi! I am a beginner in Verse. How do I call the function if I want to subscribe to it as is? Like if I don’t want to create a trigger?

Like this:

# Code

## 

Teams(Agent:agent):void =  
TeamCollection := GetPlayspace().GetTeamCollection()  
if:  
AgentsTeam := TeamCollection.GetTeam[Agent]  
then:  
TeamsArray := TeamCollection.GetTeams()  
for (TeamNumber-\>Team : TeamsArray):  
if (AgentsTeam = Team):  
Print(“This is team {TeamNumber}”)  
if (TeamNumber = 0):  
Print(“This is team 1”)  
else if (TeamNumber = 1):  
Print(“This is team 2”)

## 

And then when I want to call it, what do I write in the brackets?

Teams()

---

<div class="post-metadata">

**Author:** ![bananna\_manuk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bananna\_manuk](https://forums.unrealengine.com/u/bananna_manuk)\
**Post date:** [January 4, 2024, 6:15pm UTC](https://forums.unrealengine.com/t/calling-functions/1586921/2 "2024-01-04T18:15:31Z")

</div>

so you would pass an agent to your function

```auto
Teams(Agent)

```

by using a trigger and subscribing to the triggered event it sends the agent that triggered it automatically

by manually calling the event in verse you need to declare the agent you wish to pass to your function

---

<div class="post-metadata">

**Author:** ![pgeri04](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@pgeri04](https://forums.unrealengine.com/u/pgeri04)\
**Post date:** [January 5, 2024, 8:11am UTC](https://forums.unrealengine.com/t/calling-functions/1586921/3 "2024-01-05T08:11:47Z")

</div>

Yeah, I already tried this, but it says Unknown identifier ‘Agent’

---

<div class="post-metadata">

**Author:** ![bananna\_manuk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bananna\_manuk](https://forums.unrealengine.com/u/bananna_manuk)\
**Post date:** [January 5, 2024, 5:56pm UTC](https://forums.unrealengine.com/t/calling-functions/1586921/4 "2024-01-05T17:56:38Z")

</div>

bear in mind im no expert and this is only what i believe to be true i’m sure there are better ways of doing this so please chime in if i’m wrong or there is a better way

for your function to work you need to pass it an agent  
you get the agent from the player or ai

so you create a variable `MyAgent` then you need to tell verse what that varible is

if you want to identify a specific agent you need to have a way telling verse how to find it then you can set it to `MyAgent` then call your function using `Teams(MyAgent)`

eg

```auto
Players := GetPlayspace().GetPlayers()
              for (MyAgent : Players):
                Teams(MyAgent)  

```

this will pass all the agents in the Players array to your function, but you probaly need a way of identifing which agent is the agent you want to pass to your function

by using a trigger all this work is done for you and the agent is passed to your function via the Subscribe

hope this helps

[edits] correcting code

---

<div class="post-metadata">

**Author:** ![pgeri04](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@pgeri04](https://forums.unrealengine.com/u/pgeri04)\
**Post date:** [January 8, 2024, 8:05am UTC](https://forums.unrealengine.com/t/calling-functions/1586921/5 "2024-01-08T08:05:03Z")

</div>

That might be it, thank you!

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [February 7, 2024, 8:05am UTC](https://forums.unrealengine.com/t/calling-functions/1586921/6 "2024-02-07T08:05:04Z")

</div>

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