Hello, I am using a loop: to SpawnCar() every x seconds at a position that updates every x seconds. I was confused that the cars were always spawning at the same location even though the variable they reference for position is getting updated. To double check that I’m not tweaking, I print out the variable when it gets updated, as well as when it gets referenced in the spawner function. AND IT PRINTS TWO DIFFERENT VALUES! It does not get changed anywhere else, and starts at -50k. Here is the code and debug log, is this a bug or am I missing something? I even tried assigning the value to a new variable every loop with same results.
TrafficLoop()<suspends>: void =
Print("Traffic Started!")
loop:
if(trafficActive = true and Cars.Length < maxCars):
SpawnCar()
#check if race still going
if(raceActive = true):
Print("end!")
break
#sleep before spawning next
else Sleep(loopFreq)
SpawnCar(): void =
lane : int = GetRandomInt(0, 2)
if(chosenLane := lanes[lane]):
#where we spawning?
xPos := chosenLane.GetTransform().Translation.X
yPos := carSpawnPos
zPos := 1.0
spawnPos := vector3{X:= xPos, Y := yPos, Z:= zPos}
#spawn car!
newSpawn := SpawnProp(carProp, transform{Translation := spawnPos })
#store
if:
newCar := newSpawn(0)?
newArray := Cars + array{newCar}
set Cars = newArray
then:
Print("{carSpawnPos}")
#This gets called from another verse device TrafficManager every x seconds
ReceiveFirst<public>(posY : float): void =
set carSpawnPos = posY - trafficSpawnDistance
Print("{carSpawnPos}")