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.
About #1 what should i do instead ? Create a list with all the players and update it ?
About #2 so the Team_Manage.TeleporterNum won’t increment above the array length
About #3 OK, just looked up what hard coded indexes are, and got it
About #4 & #5 Got it.
About #6 I will read more about it !
About #7 Same question as #1
Make a player manager device. Put a map object in it. Put all your spawners in it (the device) as editables. (Make sure you add 1 more spawner than the maximum number of players.) Subscribe to player added, player removed, and player spawned events. When a player shows up (either by spawning in or the player added event), see if they are in the map and if they aren’t add them. When a player leaves (player removed event) find them in the map and remove them.
The map object is your “list” of players. Look them up using agent to get player, then use player as an index to get your “custom” player object that has all of the stuff you want to keep track of about the player. (You’ll need to make a unique class for that.)
There should be videos on YouTube about how to keep track of players (via custom player maps). Look up Warforge, Graeme Bull, and there are probably some others.
In regards to my comments about fort_character, if/when you find yourself using GetFortCharacter[] (for a valid reason, of course) - just make sure you use IsActive[] on the result to make sure it is actually valid.