AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Global var in Stock (https://forums.alliedmods.net/showthread.php?t=332543)

Crackhead69 05-18-2021 05:53

Global var in Stock
 
Hello!
How could i put a global in a stock or is it even possible.
I have searched for some time and haven't found information on this
For example:
PHP Code:

#include <amxmodx>

public plugin_init()
    
register_clcmd("say /trigger","SetTargetInfo")
    
public 
GetTarget(id){
    
get_client_info(id20)
}

stock get_client_info(idsomevar[]){
    if(
somevar[id] == 20){
        
client_print(0print_chat"Debug1")
    }


When in this situation the "somevar" is suppose to be global

Celena Luna 05-18-2021 07:33

Re: Global var in Stock
 
As long as you make it global, you can use it anywhere

PHP Code:

#include <amxmodx>

new somevar[33]

public 
plugin_init()
    
register_clcmd("say /trigger","SetTargetInfo")
    
public 
GetTarget(id){
    
get_client_info(id20)
}

stock get_client_info(idsomevar[]){
    if(
somevar[id] == 20){
        
client_print(0print_chat"Debug1")
    }



Crackhead69 05-18-2021 07:40

Re: Global var in Stock
 
So it can only be called as global if its defined?

Bugsy 05-18-2021 08:53

Re: Global var in Stock
 
It's a function, not a stock. Stocks should be defined only in include files and they are compiled in the binary (.amxx) only if they are called in code. So if you have an include file with 100 stocks but your plugin only calls one of them (and that one stock does not use any of the other stocks), then 99 of them are excluded in the .amxx at compile time.

If you want a variable accessible throughout your plugin then you declare it globally at the top of your plugin. If you want the variable accessible in only one function, then you declare it within the function.

HamletEagle 05-18-2021 12:15

Re: Global var in Stock
 
Quote:

Originally Posted by Crackhead69 (Post 2747181)
So it can only be called as global if its defined?

Of course you have to create a variable before you can use it.


All times are GMT -4. The time now is 02:32.

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