Load-Once Function
Hello!
I can't test code right now so, I would like to know, how can I make so a function is only called ONCE (it's a load function that registers stuff, therefore calling it twice registers stuff twice). Edit: I think it's worth mentioning that the function is called by multiple plugins. Thanks in advance, Vitor. |
Re: Load-Once Function
PHP Code:
|
Re: Load-Once Function
Quote:
|
Re: Load-Once Function
Quote:
Somehow if you would add a public tag the static var would be usable not only in the whole plugin but also in other plugins. Somehow it would never change the static property, so doing a different variable for every plugin you'd need some other way. |
Re: Load-Once Function
Thanks for the clearing up, Snow. I wasn't sure about the environment plugins were executed in, it's nice to know they're all in the very same one.
|
Re: Load-Once Function
Declaring a variable as static within a function will make that variable retain the value even when the function exits. The next time the function is called, the value (if any) from a previous call will remain. The variable is only accessible from within the function where it is declared unless it is passed byref to another function and is changed there; see below.
PHP Code:
|
Re: Load-Once Function
Thanks for the explanation, Bugsy, but that was not quite the point. The scripts must be executed by AMXX inside an environment, and I wasn't sure whether they were all executed in the same environment (making public globals accessible by other scripts, for instance, and static variables unically static at all scripts) or in separate environments (computationally exepensive anyway).
Thanks anyway :) |
Re: Load-Once Function
Turns out you guys were wrong about it. Making it static didn't help in any way, it is only static inside THAT environment. I need a way that will let a function to be called only once (it is an include file, therefore it is compiled twice, once in each of the two plugins using it).
|
Re: Load-Once Function
Oh yea? Test this plugin and see if it works.
Code:
|
Re: Load-Once Function
I've already done that, Exolent.
|
| All times are GMT -4. The time now is 22:41. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.