A type of global variable
Hi guys,
I'm wanting to check to see how many people are in the game at the start of each round. But also allow all functions to have access to this variable at any time. Code:
stock GetRealClientCount( bool:inGameOnly = true ) {Code:
roundStart() |
Re: A type of global variable
Use get players.
PHP Code:
|
Re: A type of global variable
The issue isnt counting the players but sharing the output with all other functions
|
Re: A type of global variable
Code:
this will return the number of players connected anytime its called. example Code:
|
Re: A type of global variable
Sorry, I don't think I'm explaining myself very well.
I can call how many players are in the game. But I'm wanting to limit the amount of times the server does the count. So instead of in each new function scanning to see how many players are in the game I want to see how many players are in the game at the start of the round. Then have that value in a global variable and use it in other functions. So scanning for the amount of players isnt the issue, but reducing the amount of times that function is called is. |
Re: A type of global variable
If you declare the variable as a global variable, you can access it wherever you want.
PHP Code:
|
Re: A type of global variable
Quote:
But, remember that you need to consider that race conditions can be created when doing this so you need to make sure that every function that relies on this number is executed after it is updated. |
Re: A type of global variable
Is that code for SourceMod?
|
Re: A type of global variable
PHP Code:
|
| All times are GMT -4. The time now is 19:10. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.