Jump to content
  • Advertisement
Beastinlosers

C++ How to move players up and down an array

This topic is 377 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Imagine a ladder with players up and down it. The better go towards the top, and the worst are at the bottom. These are constantly switching up and down, so when an event is triggered, I can grab the lowest on the ladder move them to spectator (perma death).

My problem is how can I write code in a way that will allow me to move them up and down. In Update() should I just check where they are on the leaderboards and reassign numbers, shifting everyone down. What is a good way to do this?

Share this post


Link to post
Share on other sites
Advertisement
2 hours ago, Beastinlosers said:

In Update() should I just check where they are on the leaderboards and reassign numbers, shifting everyone down.

If you can just check where they are, doesn't that mean they are already in a correctly sorted array?

Anyway, I wouldn't put the moving up & down in Update. Put it wherever the score* is changed -- that's the only time the standings can change. The only thing I might want to put in Update is if you are displaying or animating the actual transition (if you can see players slide around in the ladder instead of just instantly always being in the correct spot).

I would probably just bubble sort from the affected player, with an early out if standings don't change.

 

*score being points or whatever metric you are using to sort the array.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!