AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Can a global variable change while being used inside a public? (https://forums.alliedmods.net/showthread.php?t=300002)

eyal282 08-01-2017 17:33

Can a global variable change while being used inside a public?
 
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?

jimaway 08-01-2017 18:00

Re: Can a global variable change while being used inside a public?
 
no. there will never be 3 printed. amxmodx uses 1 thread

eyal282 08-01-2017 18:08

Re: Can a global variable change while being used inside a public?
 
Quote:

Originally Posted by jimaway (Post 2539150)
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?

fysiks 08-01-2017 22:24

Re: Can a global variable change while being used inside a public?
 
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.


All times are GMT -4. The time now is 23:09.

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