I use teleport devices to move players to specific locations. I loop through all the players and teleport each one right away, but sometimes one or two players don’t get teleported. What might be going wrong?
this is the code i used:
set Team_Manage.TeleporterNum = 0
for (Player : GetPlayspace().GetPlayers()):
TeleportToTeamSelection(Player)
set Team_Manage.TeleporterNum += 1
and now i want to test the code below but before i publish the changes i want to ask you guys if it is a known issue?
You’re incrementing TeleporterNum twice, so you’re probably ending up trying to fetch a teleporter that doesn’t exist in the array, also you might want to use this method to avoid fetching indexes out of array length
# Returns the remainder of `X/Y` as defined by Euclidean division, i.e.:
# * `Mod[X,Y] = X - Quotient(X/Y)*Y`
# * `0 <= Mod[X,Y] < Abs(Y)`
# Fails if `Y=0`.
Mod<native><public>(X:int, Y:int)<computes><decides>:int
I looked it up, and I see now. This will cycle back to the first teleporter in the array once it hits the last one.
This is really useful. I can apply it to other things. Thanks!
Honestly, I still don’t quite see where the double increment is happening. I’ve got 16 teleporters in the map of max 16 players, yet even with only 4 players, sometimes one isn’t teleported so i dont know what to think. I’m more curious about why this is happening than focused on fixing it lol
Ah, I see… that’s on me. I realize the post got a bit messy. The first code is what I’m currently using, while the second(the screen shot) is the one I plan to test out. The issue remains unclear though, because if it’s not double incrementing, then something else must be causing it.
In any case, you’ve got some assumptions there that you should not be doing. You gotta remember Verse is failable. A. You gotta always assume that everything might fail. Because it can and will. B. GetPlayspace() is a scary function that you better have a reason for using it. And you better know what you are doing with it. Maybe you do, maybe you don’t. I don’t know. C. You have an assumed += which goes back to A. I would rethink this blurb of code if is important to your game and replace it with a better function.