There are a few different errors here. First of all, I assume that you have indented your program properly and that itâs just a copy paste issue.
Secondly, the OnBegin event is part of the creative_device class, which means we must override it. We can do that pretty easily;
OnBegin<override>()<suspends>:void=
The main thing that stood out, is the syntax that you used in the calling of AddToTeam()
. I think youâve misunderstood something here;
# Functions must specify the types of parameters
foo(Argument1 : string):void=
Print(Argument1)
OnBegin<override>()<suspends>:void=
# But we don't have to specify them when we call the function,
# the compiler already knows because of the definition!
foo("Hello World")
# NOT THIS (ERRORS)
foo(Argument1 : "HelloWorld")
So letâs quickly change that;
AddToTeam(Player, 4)
What's a parameter and an argument?
The values that are declared within a function when the function is called are known as an argument. The variables that are defined when the function is declared are known as parameters.
(https://byjus.com/gate/difference-between-argument-and-parameter-in-c-and-c-plus-plus/)
Youâll quickly notice that it still doesnât work! There are a few reasons for this:
- The compiler doesnât know what AddToTeam is nor where itâs located
- The compiler doesnât know what team
4
is
You mention the verse documentation, but most of the time it can be much quicker and sometimes more insightful to just look in the Verse/UnrealEngine/Fortnite.digest.verse files. In this case, I simply searched for AddToTeam in the Fortnite.digest.verse file and found:
This means, that AddToTeam is a part of the fort_team_collection class. It also says in the comments, that we can get the team collection from fort_playspace.GetTeamCollection()
.
In the function definition of AddToTeam()
it says InTeam:team
as one of the parameters. By the verse syntax, we know that it now wants an argument of type team
to run the function - not an integer! (in your case 4)
So, with that knowledge we can now rewrite that part of the program. Keep in mind the new syntax that you learned around calling functions;
GetPlayspace().GetTeamCollection().AddToTeam(Player, ?)
So, now we only need one variable⌠but how do we get the fourth team? If we again look at the fort_team_collection
in Fortnite.digest.verse, weâll find the first function declared, GetTeams
:
The expression after :
is used to identify what the function is returning (:int
, :void
or in this case :[]team
). That means, that itâs returning a list of teams. In this list, we would want the fourth team, which would be at index 3 (lists start at index 0).
So, to get the fourth team, we would simply write:
# keep in mind that it indexes 3 which means it
# has a risk of erroring, that we must remove in verse
Playspace.GetTeamCollection().GetTeams()[3]
Now, with a little bit of tidying up, the final script would look something like this (remember your includes!):
OnBegin<override>():void=
Playspace := GetPlayspace()
# I'll make it a variable, as we use it more than once
TeamCollection := Playspace.GetTeamCollection()
# Get all players and loop through
AllPlayers := Playspace.GetPlayers()
for ( Player : AllPlayers ):
# Get the specified team and add the player to it!
# These are both deciding functions, which means they can error.
# Therefore, we must wrap them in an if statement,
# to remove any risk.
if (
FourthTeam := TeamCollection.GetTeams()[3],
TeamCollection.AddToTeam[Player, FourthTeam]) { }
Hope that helps