Hi fellow coders!
I’m learning Verse on the fly and drinking from a firehose. Only way to learn! I come from a strong background of Java and Python (and SAS) but am having some issues with syntax due to the functional nature of this. Yes, it’s familiar to Python but it’s not the same as far as thinking.
So, here’s what I’m trying to do. I have a round device I want to use to control the game specifics but trying to add some extra functionality to control Last Player Standing, End Round, Game, etc.
I’m essentially wanting to turn on the zone and then count players that leave (by elimination or game) by creating arrays of the teams and once they are filled I know that the team is eliminated and the inverse, I know who’s won the game. There might be a totally different or better way to go about this because my thinking is geared toward OOP. Is everything passed by value? Also, I realize many objects are immutable, so I saw a video on having to assign it to a new Array and then reassign it back.
Here is what I have so far:
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Fortnite.com/Teams }
using { /UnrealEngine.com/Temporary/Diagnostics }
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.
# A Verse-authored creative device that can be placed in a level
round_player_counter_device := class(creative_device):
@editable
PlayerCountedDevice : player_counter_device = player_counter_device {}
var Team1: []agent = array{}
var Team2: []agent = array{}
var Team3: []agent = array{}
var Team4: []agent = array{}
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
# TODO: Replace this with your code
PlayerCountedDevice.RemovedEvent.Subscribe(OnPlayerEliminated)
OnPlayerEliminated(Agent:agent):void=
if(Player := player[Agent]):
TeamCollection := GetPlayspace().GetTeamCollection()
if(
PlayerTeam := TeamCollection.GetTeam[Player],
PlayerAllies := TeamCollection.GetAgents[PlayerTeam],
VerseTeamIndex := TeamCollection.GetTeams().Find[PlayerTeam],
TrueTeamIndex := VerseTeamIndex + 1
):
#for(Ally : PlayerAllies):
# DO STUFF
if(TrueTeamIndex = 1):
AddPlayerToEliminatedTeam(Team1, Agent)
#consider making a class out of eliminatedTeam with flag of eliminated
AddPlayerToEliminatedTeam(TeamArray:[]agent, Agent:agent):void=
TeamMemberCount := TeamArray.Length
if( TeamMemberCount < 4 ):
if( NewArray := TeamArray.Insert[TeamMemberCount-1, array{agent}] ):
set TeamArray = NewArray
.
.
.
It doesn't like the set TeamArray -> The assignment's left hand expression type `[]agent` cannot be assigned to(3509)
TeamArray:[]agent
also when I hover over the Team1 being passed into my function it seems to think its not an array?
round_player_counter_device:)Team1:agent