Raised This Month: $ Target: $400
 0% 

Can a global variable change while being used inside a public?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
eyal282
Veteran Member
Join Date: Aug 2011
Old 08-01-2017 , 17:33   Can a global variable change while being used inside a public?
Reply With Quote #1

Code:
#include <amxmodx>

new CoolVariable;

public plugin_init()
{
    register_clcmd("Dab", "DabMaster");
    register_clcmd("Dab", "DabMaster2");
}

public DabMaster()
{
    CoolVariable = 3;
}

public DabMaster2()
{
    CoolVariable = 5;

    client_print(0, print_chat, "%i", CoolVariable);
}
In this example code, will there ever be a print of 3 instead of 5? Can 2 publics be called simultaneously?
eyal282 is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 08-01-2017 , 18:00   Re: Can a global variable change while being used inside a public?
Reply With Quote #2

no. there will never be 3 printed. amxmodx uses 1 thread
jimaway is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 08-01-2017 , 18:08   Re: Can a global variable change while being used inside a public?
Reply With Quote #3

Quote:
Originally Posted by jimaway View Post
no. there will never be 3 printed. amxmodx uses 1 thread
So it is efficient when I want to format(ex) items of a menu to use a global variable, am I right?
eyal282 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-01-2017 , 22:24   Re: Can a global variable change while being used inside a public?
Reply With Quote #4

Global variables can be set from anywhere and used from anywhere. Your last question doesn't make sense but I hope it's clear from either of our statements.
__________________
fysiks is online now
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 23:09.


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