AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Variables between functions (https://forums.alliedmods.net/showthread.php?t=253571)

Kazalu 12-24-2014 10:42

Variables between functions
 
HTML Code:

public ctwin()
{
        CTrounds++;
        //return CTrounds;
}

public twin()
{
        Trounds++;
        //return Trounds;
}

public cmdScore( id )
{
        CTrounds = ctwin();
        Trounds = twin();
}

How can I get the return value of those functions, without modifying the variables in the process?

I mean, if I try to get Trounds in the cmdScore function, it will also add 1 to the variable value.

YamiKaitou 12-24-2014 10:52

Re: Variables between functions
 
If they are global variables, then just access them directly

Kazalu 12-24-2014 11:00

Re: Variables between functions
 
Will they keep their values?
Like, if it was modified in a function, will it be modified in all the functions?

YamiKaitou 12-24-2014 11:08

Re: Variables between functions
 
There is only 1 copy of a global variable, so it will always return the same value regardless of which function you access it in. The same is true if you change the value of it in 1 function, all subsequent checks of the variable will return the new value

Kazalu 12-24-2014 11:11

Re: Variables between functions
 
Thank you very much, sir!


All times are GMT -4. The time now is 15:19.

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