AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Static variables (https://forums.alliedmods.net/showthread.php?t=76664)

Prajch 08-28-2008 10:18

Static variables
 
If I write something like
PHP Code:

public client_connect(id)
{
   static 
authid[35]
   
get_user_authid(idauthid34)
 
   ...


Is it possible that the contents of authid are overwritten before the entire routine has been executed?

danielkza 08-28-2008 12:00

Re: Static variables
 
Static variables are just like global variables,but with a local scope.Once you assign something to them, it will stay there until you do it again.

Prajch 08-28-2008 12:12

Re: Static variables
 
I guess a better question would be whether it's possible for client_connect (in this case) to be called again before the first call is finished, thus overwriting authid.

danielkza 08-28-2008 12:43

Re: Static variables
 
Quote:

Originally Posted by Prajch (Post 677315)
I guess a better question would be whether it's possible for client_connect (in this case) to be called again before the first call is finished, thus overwriting authid.

No, HL is single-thread,nothing will run until your function finishes.

Prajch 08-28-2008 13:09

Re: Static variables
 
Ok thank you.

Silencer123 08-28-2008 16:21

Re: Static variables
 
You by the way cannot return authid in client_connect.(id)
The earliest moment you can do so is client_authorized(id).

Brad 08-28-2008 16:30

Re: Static variables
 
It's also not necessarily worth it to use a static variable in this particular case as the forward isn't get called excessively nor is your variable of an excessive length.

If you ran a timing test, you wouldn't notice much of a difference, if any, unless you ran it an absurd number of times.

Prajch 08-28-2008 16:59

Re: Static variables
 
It was just an example; I was more interested in other cases, but thanks for the extra tips.

Exolent[jNr] 08-28-2008 17:11

Re: Static variables
 
The Use of Static Variables


All times are GMT -4. The time now is 03:07.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.