![]() |
Help with Global Variables - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html) +---- Thread: Help with Global Variables (/thread-11597.html) |
Help with Global Variables - flamez3 - 12-01-2011 Hey, This is the first time I've ever used Global Variables, and I'm having some troubles with Global variables. This is what I've added to both script files I want the global variable to apply on. This is not all of the script, only the parts that include the global variables. Map 1: Quote:void OnStart()Map 2: Quote:void OnStart()Again, these are not the full .hps files because I don't want to ruin anything (and there's alot of lines). There are NO fatal errors it works perfectly, but once I do what I'm required by the script, it loads the other map and the elevator door is still locked. Any information about this would be very helpful. Thanks ![]() RE: Help with Global Variables - Obliviator27 - 12-01-2011 You need a global.hps file in the main custom story directory (The one with your extra_english and custom_story_settings.cfg file) And it should look like Code: void OnGameStart() ![]() RE: Help with Global Variables - flamez3 - 12-01-2011 (12-01-2011, 09:05 AM)Obliviator27 Wrote: You need a global.hps file in the main custom story directory (The one with your extra_english and custom_story_settings.cfg file)Does that mean that I put Quote:void func_on()under the void OnGameStart place? Once I've added the SetGlobalVarInt("GlobalVar1", 0); inside the void OnGameStart RE: Help with Global Variables - Obliviator27 - 12-01-2011 It works like this. Code: void OnGameStart() Code: void func01() RE: Help with Global Variables - Your Computer - 12-01-2011 You don't need a global.hps for global map variables to work. The issue here is that the code logic is wrong. This is the kind of scenario where OnEnter() comes in to play. You appear to have the same func_on function in both maps when it isn't required in any. The goal you're showing me is simple: you want a certain door to be unlocked when the user interacts with a valve in another map. You've done right by trying to set a global map variable within the connection state chage callback, but that is pretty much all that was needed for the connection state change callback. Therefore the valve_func1 function should look something like this: PHP Code: void valve_func1(string &in asEntity, int alState) Next you're going to want to remove the func01 function from your scripts, as they are not needed. In your OnEnter function you'll be checking if the global map variable has been set, and if it is set, unlock the door. Therefore make sure your OnEnter function looks something like this: PHP Code: void OnEnter() Since you didn't clearly specify which map contains the elevator door, i'm going to leave you to put this for the map that contains the elevator door. One final thing i need to mention: All map variables by default equate to 0, at least the ones that deal with numbers (strings would be an empty string). Therefore there is no need to set a global or local map variable to 0 in OnStart (or anywhere else), that is, unless they are not currently at 0 and you want to reset the value. |