env_global - variables across many maps? Created 8 years ago2016-02-02 08:56:31 UTC by Dallas Dallas

Created 8 years ago2016-02-02 08:56:31 UTC by Dallas Dallas

Posted 8 years ago2016-02-02 10:25:21 UTC Post #328632
I have a question about env_globals.

This is for standard hl1 goldsource on steam.

I have 4 maps that play linearly in order. The level transitions are 1 way.

I want to set a variable in the 1st map, and then do something with it in the 4th map.

Imagine I have a button in map 1, and I want to unlock a door in map 4. What do?

If I set up an env_global in map 1 and target it/set its variable, will that global state be available in the 4th map? Or, will I need to set an env_global in each map to carry the variable from map to map?

The tutorial here on twhl seems great for a 2 map scenario, so I'm wondering how to scale it.

Thanks for your help :)
Posted 8 years ago2016-02-02 11:55:31 UTC Post #328633
Hm not sure myself but why don't you just create a quick test series 4 maps each consisting of 2 small rooms and in the 4th you've got your extra door. Test it with and without the env_global setting enabled. Creation time 5 minutes for the map transitions and 2 rooms with copy and paste.

Test time 15 seconds to run from map to map. :P
Posted 8 years ago2016-02-02 15:17:50 UTC Post #328635
I think you need the same global in each map that references the data. So if you're only using that trigger in maps 1 and 4, map 1 and 4 should have the same global.
Tetsu0 Tetsu0Positive Chaos
Posted 8 years ago2016-02-03 08:30:59 UTC Post #328637
Thanks guys. I'll mock it up and report back.
Posted 8 years ago2016-02-03 23:35:37 UTC Post #328650
Hey Dallas I did dome additional research and testing; I have it all figured out now. I was totally wrong before.

Here's your setup:

[blue]-Map 1-[/blue]
Entities Required:
func_button
Target: env_global name
Delay before reset: -1

env_global
global state to set: unlock_door
trigger mode: on
Initial state: off

The button or trigger works best as a one-shot so you can lock the "on" state of your trigger (don't have the button reset).
"Global State to Set" is essentially a variable name. You'll want to keep track of these global variables on a notepad or something so you don't overwrite anything.
"Initial state" is easy enough to figure out; The global variable will default to off.
"trigger mode" is which state you want to set when the env_global is triggered. So when we trigger this env_global, the variable "Unlock_door" will be set to "on" (or 1).

[blue]-Map 4-[/blue]
Entities Required
Multisource
name: door_master

trigger_auto
delay before trigger: 1
target: door_master
global state to read: unlock_door (the global variable)
trigger state: off
Flags
Remove On Fire: FALSE![Important!!]

func_door
master: door_master

Ok the important thing to note here is things just don't happen automatically and we need that trigger auto. The trigger_auto activates 1 second after the map loads (this happens every time which is why it's important to un-tick the "remove on fire" box, else it'll only trigger once). When the trigger_auto tries to fire, it will check the status of your global variable. If the global variable is set, the multisource will become active and this will unlock the door and make it usable.
Tetsu0 Tetsu0Positive Chaos
Posted 8 years ago2016-02-04 09:20:20 UTC Post #328657
Thanks for the research Tetsu. This is great.

Its interesting that we need the trigger_auto - I wonder why the "Global State Master" setting on the multisource set to "unlock_door" does not work like it does with just 2 maps.
Posted 8 years ago2016-02-04 13:30:37 UTC Post #328660
I think the globals arent read unless something is trying to be triggered. I don't think the engine scans through the variables and decides whats on or off.. A trigger seems like an impulse, a single event.
The global was set in one event, but since we changed maps, there needs to be another event action/impulse that tries to read the data.
I tried probably 8 different setups but only the trigger auto worked.
Seeing as how you need to transition maps anyway, the trigger auto serves as our impulse event to try and read that global on map change.
Also this setup is for an automatic trigger.
If you wanted to open the door with a button, you need to trigger a multisource that reads the global variable
Tetsu0 Tetsu0Positive Chaos
You must be logged in to post a response.