Hey there!
In my current code I have 2 arrays included:
@editable SpawnerArray : []player_spawner_device = array{}
@editable MenuArray : []cinematic_sequence_device = array{}
I want for every player_spawner_device
a specific cinematic_sequence_device
.
For example if a player spawns on a player spawner device with the index 0, it should show the cinematic sequence with the same index & so on…
Greetings!
Why not use a Map instead? I would suggest taking a look at TMap<KeyType, ElementType>
Map Containers in Unreal Engine | Unreal Engine 5.1 Documentation
That way you can map players to cinematic sequence devices, such that given any player, you get their cinematic sequence device returned.
1 Like
But isn’t that just for C++ & not for Verse? Because I can’t find anything similar to this in the Verse Glossar
Verse has built-in map data types which you use to define key value pairs. For example, if I wanted to map Ids to Players I could make:
# Create a map that holds an integer for every player variable
PlayersToID : [player]int = map{}
# If I wanted to acces a Player's ID
PrintPlayerID(Player : player) : void =
# Here, we acces the id that corresponds to the player we passed in
# This ID gets assigned to PlayerID
# Note that to access elements in a map, you must do so in an if expression
if (PlayerID := PlayersToID[Player]):
Print("Your player ID is {PlayerID}")
Now one important note is that you generally cannot create maps where the Key is a device, for example
# This throws an error, because devices are not comparable, and maps must
# have unique keys per entry, which you must somehow be able to compare
SpawnersToCinematicsMap : [player_spawner_device]cinematic_sequence_device = map{}
1 Like
You could make an array of type tuple(player_spawner_device, cinematic_sequence_device)
If you want it to be a bit more readable so you don’t need to type (0), or (1), you could make a class/struct
spawner_and_cinematic := struct:
SpawnerDevice : player_spawner_device = player_spawner_device{}
CinematicDevice : cinematic_sequence_device = cinematic_sequence_device{}
MyArray : []spawner_and_cinematic = array{}
4 Likes