I am creating assets in Verse and storing them in a one dimensional array. This example creates 10 assets. I then dispose of some of them randomly. The tiles that match the criteria for disposal are disposed. The problem is that other that don’t fit the criteria are also disposed even though there is no print out to mark the disposal.
I adapted this code from a youtuber’s version related to two dimensional arrays. His works and mine seems to do way more than desired.
Any ideas why more tiles than requested are destroyed?
using { /Fortnite.com/Devices }
using { /Verse.org/Native }
using { /Verse.org/Random }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
game_device := class(creative_device):
# asset is used in each tile cell
@editable var TileAsset : creative_prop_asset := DefaultCreativePropAsset
# single dimension array for testing tile asseet creation/disposal
var TileArray: []?creative_prop = array{}
OnBegin<override>()<suspends>:void=
Print("onBegin")
GenTiles(10)
Sleep(5.0)
DisposeRandomTile()
CreateCell(Index:int):?creative_prop=
Spacer := 610.0
if (Xp := float[Index * Spacer], Yp := 0.0):
return SpawnProp(TileAsset, vector3{X := Xp, Y := Yp, Z := 140.0}, IdentityRotation())(0)
else:
return false
DisposeRandomTile()<suspends>:void=
for (Index := 0..TileArray.Length - 1):
if (Tile := creative_prop[TileArray[Index]?]):
Rand := GetRandomFloat(0.0, 3.0)
Print("Cell [{Index}] with Rand: {Rand}")
if (Rand <= 1.0):
Tile.Dispose()
Print("Disposing cell: [{Index}] because {Rand} <= 1.0")
GenTiles(Number:int):void=
set TileArray =
for (Index := 0..Number - 1):
CreateCell(Index)