So I have an verse script that is supposed to keep track of which checkpoint a player is on, and later respawn him in that checkpoint. But no matter what I do the map keeps being empty and no value is stored in it, so I can’t proceed with the respawn logic.
team1_manager := class(creative_device):
@editable
RaceCheckpoints : []race_checkpoint_device = array{}
var PlayersRef : [player]int = map{}
var Player1Checkpoint : []int = array{0}
#var PTranslation : (vector3, vector3) = vector3.zero
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
Sleep(1.0)
Print("Team1 Manager Started")
AllPlayers := GetPlayspace().GetPlayers()
for (TeamPlayer : AllPlayers, CurrentTeam := GetPlayspace().GetTeamCollection().GetTeam[TeamPlayer]):
if(CurrentTeam = 1):
if(set PlayersRef[TeamPlayer] = 0, Checkpoint := PlayersRef[TeamPlayer]):
Print("Player checkpoint is {Checkpoint}")
for (players := 0..PlayersRef.Length):
Print("Player {players} is on Team 1")
Print("Player map size: {PlayersRef.Length}")
for (Checkpoint : RaceCheckpoints):
Checkpoint.CheckpointCompletedEvent.Subscribe(ClearedCheckpoint)
#end for
ClearedCheckpoint<private> (Agent : agent):void=
#Print("Cleared Checkpoint")
if(value := PlayersRef[Agent]):
Print("Player Cleared {value} Checkpoints")
else:
Print("Player not in map, map size: {PlayersRef.Length}")
for(Key -> Value : PlayersRef):
Print("Key: player0 Value: {Value}")
if (Key = player[Agent]):
Translation := vector3
index := 0
if:
set Player1Checkpoint[Value] = Player1Checkpoint[Value] + 1
index = Player1Checkpoint[Value]
#set Translation = RaceCheckpoints[Player1Checkpoint[Index]].GetTransform().Translation
Rotation := RaceCheckpoints[Player1Checkpoint[Value]].GetTransform().Rotation
#Respawn(Players, Translation, Rotation)
Print("Checkpoint saved: {index}")
#end if
When the game starts, sometimes it does’t even print the requested prints and when it prints, it says that a player is in team 1 but the Player map size is 0.