Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with Global Variables
flamez3 Offline
Posting Freak

Posts: 1,281
Threads: 48
Joined: Apr 2011
Reputation: 57
#1
Help with Global Variables

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()
{
SetGlobalVarInt("Globalvar1", 0);
}

void func_on()
{
if(GetGlobalVarInt("Globalvar1") == 1)
{
SetSwingDoorLocked("elevator_door_1", false, false);
}
}
Map 2:


Quote:void OnStart()
{
SetGlobalVarInt("Globalvar1", 0);
SetEntityConnectionStateChangeCallback("valve_iron_1", "valve_func1");

}


void valve_func1(string &in asEntity, int alState)
{
AddLocalVarInt("Var1", 1);
{
AddGlobalVarInt("Globalvar1", 1);
func_on();
}
}

void func_on()
{
if(GetGlobalVarInt("Globalvar1") == 1)
{
SetSwingDoorLocked("elevator_door_1", false, false);
}
}
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 Smile

(This post was last modified: 12-01-2011, 08:37 AM by flamez3.)
12-01-2011, 08:36 AM
Find
Obliviator27 Offline
Posting Freak

Posts: 792
Threads: 10
Joined: Jul 2011
Reputation: 66
#2
RE: Help with Global Variables

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


void OnGameStart()
{
Use SetGlobalVarInt as many times as you like, for as many global variables you like
}
And that's all there is to it. Smile

(This post was last modified: 12-01-2011, 09:05 AM by Obliviator27.)
12-01-2011, 09:05 AM
Find
flamez3 Offline
Posting Freak

Posts: 1,281
Threads: 48
Joined: Apr 2011
Reputation: 57
#3
RE: Help with Global Variables

(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)
And it should look like


void OnGameStart()
{
Use SetGlobalVarInt as many times as you like, for as many global variables you like
}
And that's all there is to it. Smile
Does that mean that I put


Quote:void func_on()
{
if(GetGlobalVarInt("Globalvar1") == 1)
{
SetSwingDoorLocked("elevator_door_1", false, false);
}
}
under the void OnGameStart place? Once I've added the SetGlobalVarInt("GlobalVar1", 0); inside the void OnGameStart


(This post was last modified: 12-01-2011, 09:14 AM by flamez3.)
12-01-2011, 09:13 AM
Find
Obliviator27 Offline
Posting Freak

Posts: 792
Threads: 10
Joined: Jul 2011
Reputation: 66
#4
RE: Help with Global Variables

It works like this.
void OnGameStart()
{
SetGlobalVarInt("Globalvar1", 0);
}
and then in your .hps
void func01()
{
if(GetGlobalVarInt("Globalvar1") == 1)
{
SetSwingDoorLocked("door_1", false, true);
}
}

(This post was last modified: 12-01-2011, 09:21 AM by Obliviator27.)
12-01-2011, 09:16 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#5
RE: Help with Global Variables

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: (Select All)
void valve_func1(string &in asEntityint alState)
{
    
// You may want to consider alState somewhere in here
    
AddLocalVarInt("Var1"1); // not sure what this is for, but i'll leave it
    // We SET a global map variable here, because ADDing to the variable may cause problems
    
SetGlobalVarInt("Globalvar1"1);
    
// You may want to consider naming your global variables to something more practical


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: (Select All)
void OnEnter()
{
    
// You may want to consider naming your global variables to something more practical
    
if(GetGlobalVarInt("Globalvar1") == 1)
    {
        
SetSwingDoorLocked("elevator_door_1"falsefalse);
    }


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.

Tutorials: From Noob to Pro
(This post was last modified: 12-01-2011, 11:58 PM by Your Computer.)
12-01-2011, 11:56 PM
Website Find




Users browsing this thread: 1 Guest(s)