Tutorial: Globals 1 Last edited 21 years ago2002-07-14 04:00:00 UTC

You are viewing an older revision of this wiki page. The current revision may be more detailed and up-to-date. Click here to see the current revision of this page.

This article was converted from a previous version of TWHL and may need to be reviewed

  1. The formatting may be incorrect due to differences in the WikiCode processing engine, it needs to be revised and reformatted
  2. Some information may be out of date
  3. After the article is re-formatted and updated, remove this notice and the Review Required category.
  4. Some older tutorials are no longer useful, or they duplicate information from other tutorials and entity guides. In this case, delete the page after merging any relevant information into other pages. Contact an admin to delete a page.

Download attachment

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 couse. Two, in fact, 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!

env_global

Place an 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 multisource entities can read globals, but trigger_autos are in fact another. We will be using both in this tutorial :)

The Multisource

So now we need a multisource. 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 multisource. The multisource 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 multisource 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. Trigger_auto 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 trigger_auto, just as with the multisource. 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 togglable won't work in this case. Making the trigger_auto 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.
DiagramDiagram

1 Comment

Commented 14 years ago2009-08-20 02:16:41 UTC Comment #100502
great tutorial! this got me to be able to use env_global and multisource across 2 maps! I only wish the tutorial had specifically mentioned you need the multisource in BOTH maps! (though you can see that by loading the example map) Also i wish the point of the "global state to set"/"global state master" was better a little better explained--it seemed to simple but it's probably just me.

anyway, this helped me out a lot. great tutorial!

You must log in to post a comment. You can login or register a new account.