Scope
From ZDoom Wiki
Variable scope is necessary for editing ACS, and it's also a fundamental thing you should know if you plan on programming in pretty much any language (including ACS) at some point. There are four kinds of variables in ACS, and thus four kinds of scope.
Script Scope
Any variables declared within the body of a script have script scope. That is they cannot be accessed by any scripts or functions outside of the script in which they are defined.
Map Scope
These variables are declared in a map script and can be accessed or modified by any script or function defined within the same BEHAVIOR lump.
World Scope
These variables have scope within a hub of maps (ala Hexen), so that two (or more) maps within the same hub can access and alter these variables.
Global Scope
This type of variable is accessible to all scripts and functions from any map or library.
Note that for World and Global scope variables, you must define an integer along with the variable name in the code:
// This is a normal variable (Script or Map scope): int MyVar;
// This is how a World or Global scope variable must be defined: world int 1:MyVar; global int 1:MyVar;
The number is used to store the variable value between maps. This is important because a single compiled ACS script does not share its variable names with other scripts. That is why the number is needed to identify the World or Global scope variable from one map to the next. In fact, the actual text name doesn't matter except within the current ACS lump. You could tecnically have "int 1:MyVar" in one script and "int 1:YourVar" in another script and they would actually be the same variable. This practice is not recommended, however, as it could easily lead to confusion when reading the script's source.
Examples
These are three map scripts from an imaginary pwad which has three maps, E1M1, E1M2 and E2M1. E1M1 and E1M2 are hubbed together, but E2M1 is a stand alone map.
//scripts for E1M1 of imaginary pwad
#include "zcommon.acs"
world int 1:gotkey; //world scope
global int 2:dooropen; //global scope
int counter = 0; //map scope
script 1 (void)
{
int q = 0; //script scope
while(q <= 10)
{
print(d:q);
delay(35);
counter = addTen(counter);
q++;
}
counter++;
if(gotkey == 1)
counter = addTen(counter);
if(dooropen == 1)
gotkey = 0;
}
function int addTen(int z)
{
int q = 10 + counter;
return z + q;
}
//scripts for E1M2 of imaginary pwad
#include "zcommon.acs"
world int 1:gotkey; //world scope
global int 2:dooropen; //global scope
int keycheck = 0; //map scope
script 100 (void)
{
if(gotkey == 0)
{
keycheck = checkinventory("RedSkull");
if(keycheck == 1)
gotkey = 1;
}
}
//scripts for E2M1 of imaginary pwad
#include "zcommon.acs"
world int 2:shotgun; //world scope
global int 2:dooropen; //global scope
script 200 (void)
{
if(dooropen == 1)
{
shotgun = 1;
giveinventory("Shotgun", 1);
}
}
Note that 'dooropen' can be accessed by all three maps (though it needs to be defined so ACC knows about it) whereas gotkey can be accessed by E1M1 and E1M2 but not E2M1. Note in map01 there are two different variables named q, but what happens to one has no effect on the other so when function addTen is called and it makes q into 10 + the value of counter, the q in script 1 remains unchanged.

