Raised This Month: $51 Target: $400
 12% 

Global var in Stock


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Crackhead69
Member
Join Date: Feb 2021
Old 05-18-2021 , 05:53   Global var in Stock
Reply With Quote #1

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

Last edited by Crackhead69; 05-18-2021 at 06:31.
Crackhead69 is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 05-18-2021 , 07:33   Re: Global var in Stock
Reply With Quote #2

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")
    }

__________________
My plugin:

Last edited by Celena Luna; 05-18-2021 at 07:33.
Celena Luna is offline
Crackhead69
Member
Join Date: Feb 2021
Old 05-18-2021 , 07:40   Re: Global var in Stock
Reply With Quote #3

So it can only be called as global if its defined?
Crackhead69 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-18-2021 , 08:53   Re: Global var in Stock
Reply With Quote #4

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.
__________________

Last edited by Bugsy; 05-18-2021 at 08:54.
Bugsy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-18-2021 , 12:15   Re: Global var in Stock
Reply With Quote #5

Quote:
Originally Posted by Crackhead69 View Post
So it can only be called as global if its defined?
Of course you have to create a variable before you can use it.
__________________
HamletEagle is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:58.


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