Questions about optimization and cs_set_user_team()
I want to assign everyone to a random team. This following code loops through all the players and assigns them to a random team if the team is not maxed out, otherwise it will assign them to the other team.
PHP Code:
Edit: One bonus 3rd question: Why do I always see variables in this forum start with "sz"? Like szVariableName? |
Re: Questions about optimization and cs_set_user_team()
1. Correct, you are only accessing players[] once per pass so it is fine.
2. Yeah, see the below code. For your last question, it's called Hungarian notation. It helps the developer and/or person looking at the code what type of data is held in the variable. sz being null-terminated string. PHP Code:
|
Re: Questions about optimization and cs_set_user_team()
FYI.
PHP Code:
https://forums.alliedmods.net/showthread.php?t=85274 |
Re: Questions about optimization and cs_set_user_team()
Thank you both for your answers! Bugsy's code was very enlightening.
There was also some good info on programming habits that Arukari linked that I will be reading later. One thing: I probably should have been more specific, but the following code will not increase "count[team]" if the player is already part of the randomly chosen team. This should not be the case, it should increase regardless. But I can fix that myself. Quote:
Thread marked as solved. |
Re: Questions about optimization and cs_set_user_team()
frio, your code that I edited wouldn't do this either, but I just made an edit to do so.
|
Re: Questions about optimization and cs_set_user_team()
I want to add that the "sz" thing(hungarian notation) is a matter of style and you are not required to use it. IMO it is not needed anyway as long as you make an effort to name your variables properly.
For example playersCount is clearly a number(integer), naming it iPlayersCount doesn't add any useful information and can make certain variable names too verbose. Another example: fileLine[128] is clearly a string, you know that even if it's not prefixed with sz. Anyway, as with any coding style related topic, the most important thing is to pick a style and be consitent. Don't mix multiple styles in the same code and you are good. |
| All times are GMT -4. The time now is 16:56. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.