Can someone help me? I’m a beginner and I’m only used to C# unity and verse is being very difficult for me. I have a script that is data persistence and another to organize a team in an array, and give coins to the team that wins, but I’m not able to get all the players on a team and send them as agents to another script to give the coins and save. To call the AwardTeam() that calls datapersistence.IncreaseGold(agent) and give the coins to all players on the team that are in the array.
YellowVSRed := class(creative_device):
@editable yellowtrigger : trigger_device= trigger_device{}
@editable redtrigger : trigger_device= trigger_device{}
@editable removeTeamtrigger: trigger_device= trigger_device{}
@editable datapersistence : DataPersistence = DataPersistence{}
var PlayersInYellowTeam : []agent = array{}
var PlayersInRedTeam : []agent = array{}
OnBegin< override>()< suspends>:void=
yellowtrigger.TriggeredEvent.Subscribe(OnPlayerEnteredYellowTeam)
OnPlayerEnteredYellowTeam(Agent : ?agent) : void =
if (Agent?):
PlayersInYellowTeam + array{Agent}
Print("team yellow")
AwardTeam(PlayersInYellowTeam, 10)
AwardTeam(Team: []agent, Coins: int): void =
Print("called")
for (Index := 0..Team.Length - 1): #First test option
if (Element := Team[Index]):
datapersistence.IncreaseGold(Element)
for (Player : Team):#Second test option
datapersistence.IncreaseGold(Player)
datapersistence.AddValueGold(Player, Coins)
Print("team yellow coin")
spawners := class(tag){}
TextForUI< localizes>(InText : string) : message = “Coins: {InText}”
player_data := class< final>< persistable>{
Gold : int = 0
Fun1 : logic = false
Fun2 : logic = false
}
player_data_update< constructor>(OldStat:player_data)< transacts> := player_data {
Gold := OldStat.Gold
Fun1 := OldStat.Fun1
Fun2 := OldStat.Fun2
}
var Data:weak_map(player, player_data) = map{}
DataPersistence := class(creative_device):
var PlayerMap : [agent]spawners = map{}
@editable Increase : button_device = button_device{}
@editable Decrease : button_device = button_device{}
InitSpawners():void = {
Spawners := GetCreativeObjectsWithTag(spawners{})
for (Obj : Spawners) {
if (Spawner := player_spawner_device[Obj]) {
Spawner.SpawnedEvent.Subscribe(OnPlayerSpawned)
}
}
}
OnPlayerSpawned(Agent : agent) : void = {
if (PlayerObj := player[Agent]) {
if (PlayerExists := PlayerMap[Agent]) {
} else {
if (set PlayerMap[PlayerObj] = spawners{}) {
if (not Data[PlayerObj]) {
if (set Data[PlayerObj] = player_data{}) {
Print("New Player Data Created")
}
}
spawn{UpdateValues(PlayerObj)}
}
}
}
}
IncreaseGold<public>(Agent : agent) : void = {
if (PlayerObj := player[Agent]) {
if (PlayerData := Data[PlayerObj]) {
if:
OldData := Data[PlayerObj]
set Data[PlayerObj] = player_data{
player_data_update< constructor>(OldData)
Gold := OldData.Gold + 1
}
then:
Print("Gold Increased")
}
}
}
AddValueGold<public>(Agent : agent, value : int): void = {
if (PlayerObj := player[Agent]) {
if (PlayerData := Data[PlayerObj]) {
if:
OldData := Data[PlayerObj]
set Data[PlayerObj] = player_data{
player_data_update< constructor>(OldData)
Gold := OldData.Gold + value
}
then:
Print("Gold Decreased")
}
}
}
UnlockFun1<public>(Agent : agent): void = {
if (PlayerObj := player[Agent]) {
if (PlayerData := Data[PlayerObj]) {
if:
OldData := Data[PlayerObj]
set Data[PlayerObj] = player_data{
player_data_update< constructor>(OldData)
Fun1 := true
}
then:
Print("Fun1 Unlocked")
}
}
}
OnBegin< override>()< suspends>:void=
AllPlayers := GetPlayspace().GetPlayers()
for (Player : AllPlayers) {
OnPlayerSpawned(Player)
}
Sleep(0.8)
InitSpawners()
GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoved)
Increase.InteractedWithEvent.Subscribe(IncreaseGold)
onTriggerActivated(MaybeAgent : ?agent):void=
if (Agent := MaybeAgent?):
IncreaseGold(Agent)
else:
# Your code here in case the MaybeAgent = false
OnPlayerRemoved(PlayerLeft : agent): void = {
if (Agent := agent[PlayerLeft]) {
if (ActualPlayer := PlayerMap[Agent]) {
var TempPlayerMap : [agent]spawners = map{}
for (Key -> Value : PlayerMap, Key <> Agent) {
set TempPlayerMap = ConcatenateMaps(TempPlayerMap, map{Key => Value})
}
set PlayerMap = TempPlayerMap
}
}
}