Globals are basically variables that are available across levels. They allow the player to do something in one map that has an effect in another, and they're not very difficult to set up.
What you need
A map, of course - well, two maps, which we will join together with a level transition. For the example, I just created a room with a passage leading into another room. The first room, where it all begins, has a locked door in it that won't open. In the other room, there is a lever. We want the lever to allow the door to be opened when the player returns to the first room. So far, so good.
But now we're going to split the map in two. The first map contains the first room, the level change is triggered in the passage, and the second room is in the second map. But how do we get the door in map 1 listen to the switch in map 2? That's right: a global!
Create an env_global
See also: env_global
somewhere in the second map, with the switch. Make the switch trigger it, and give it a Global State to Set
. Trigger Mode
determines what the global does when it is triggered. Dead
is for monsters, while Toggle
allows the global to be triggered on and off, starting with whatever is set as the Initial State
. If the Set Initial State
flag is enabled, the global becomes the Initial State
at startup, without having to be activated first.
Right. We're only going to allow the switch to be used once, so make Global State to Set On
. Only a few entities can read global states. In fact, the old WorldCraft manual says that only
entities can read globals, but
can as well. We will be using both in this tutorial.
- *Name*: Set a name for the entity
- *Global state to set*: Name of the entity you want to trigger from another map
- *Trigger mode*: Off, on, make the target dead, or toggle on/off
- *Initial state*: Off, on, or make this entity dead.
- *Set initial State*: Uses the initial state, otherwise its ignored.
Create a multisource
See also: multisource
• Tutorial: Multisource
Now we need a
. Create one, and set its Global State Master
to the same value as the Global State to Set
attribute of the env_global
. Also give it a name, so that our door can reference it. Then the door needs its Master
set to the name of the
basically acts as an intermediate between the global variable that's floating around, and the door. Globals can't act as masters to doors directly. Check out the multisource tutorial
for more in-depth explanation of the
and what it can be used for. This is all we need for our level though - you will find that if you walk up to the door after pulling the lever in the second map, it will open, and you will be presented with a shotgun... and Barney (tradition).
Triggering a Light
But of course, we're not going to leave it at that! What else can this thing do? How about control a light, rather than just determine whether something can be used. We want it to actively trigger
an entity, rather than just be something's master. Well, as with the door, it can, with an intermediate.
will do fine for the example, since it can read the global state. This time the property is called Global State to Read
, for no particular reason, it seems, because it acts like a master to the
, just as with the
If the global state is on
when the map loads, the light will be turned on. It will then stay on, so making the global toggleable won't work in this case. Making the
use a Toggle Trigger State
won't work either, because then the light will turn on and off every time the map is re-entered while the global is on. So for this example the switch in room two stays pressed. Notice the small Delay before trigger
value - that's to make sure the light entity has actually been spawned before it is triggered by the trigger_auto
, which prepares to trigger its target the moment the map loads. Below is a simple representation of what happens in the example.
In simple terms,
allows you to target and trigger entities across multiple maps. This is useful if multiple maps are used to complete a single task, much like the "Blast Pit" chapter of Half-Life. Let's say you want to do something like this to add depth to your mod or map series. This is the simplest way to do it.
Entities used in this example
See also: trigger_auto
- `trigger_auto`: Automatically Targets an entity by its Name when the map is loaded or certain parameters are met.
- `multisource`: Once all entities that target the same Multisource are in the ON position, this entity then Targets a new entity to be triggered.
- `func_button`: This allows the player to USE the button, which then Targets another entity.
Triggering entities in other levels
Let's say that you want to trigger a door from another map. First you would set up your door. Give it a name
of your choice. You shouldn't have to worry about the parameter Global Entity Name
for now, the normal name
will be targetted. Second, on the map where the
is, make an
After you are satisfied with your new
, set the name
as its target
. The game engine should than store the targeted Global state to set
and its Trigger Mode
, which travels with you from between maps. To use this in the other maps, make a
and assign the Global state to read
parameter to be the exact name
of the Global state to set
. Set the Trigger Mode
for now. Now, the
acts like a Master to the
. From here, you then use the target
parameter to target the entity you want triggered by the
you set on the other map.
Using multiple env_globals and a multisource
If you want multiple
to affect an entity, have the
to target a
. As an example, this is how the Blast Pit scenario was done.
You walk into the control room and realize the test-fire button doesn't work. So you sneak around the tentacles to one of the side maps. After killing many zombies and headcrabs, you stumble across the switch that turns on the oxygen to the rocket engine. This targets an
and a name and state is saved. When you return to the control room, a
reads the state and turns on the oxygen. Yet you can't fire the engine yet because the
, which is targetting a
, which the fuel, power, and test-fire switches are also targetting. Once all the switches are turned on, then the
starts the engine. It's like a chain reaction of triggers.