Frictional Games Forum (read-only)
Question about using 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: Question about using global variables (/thread-10744.html)



Question about using global variables - ggstarfoxxie - 10-14-2011

I'm having trouble with a function in one map that needs to check if a player has a key from another map, then execute a scary event only when the player has the key. I've tried the script below as a workaround, but it doesn't behave like I want it to. The "keytrigger" function will still happen, even when I don't have Catleena's key.

Code:
void OnEnter()
{
    PlayMusic("25_amb.ogg", true, 1.0f, 10.0f, 1, true);
    AddEntityCollideCallback("Player", "keycheck", "keytrigger", false, 1);
}
void keytrigger(string &in asParent, string &in asChild, int alState)
{
        if(HasItem("catleenakey")=true){
            SetEntityActive("tablechair_*", true);
            SetEntityActive("chairattable_*", false);
        }
}

I've read you have to use global variables, but I don't know how to use them properly. The wiki doesn't explain how to utilize them, just lists the functions. If someone could explain how to use globals for checking items/completed puzzles, or know of a better workaround, I'd appreciate it. Smile



RE: Question about using global variables - Your Computer - 10-14-2011

Concerning your script: it doesn't work because you're trying to assign "true" to a function. You're supposed to have two equal signs in order to return an expected boolean to the conditional if statement.


RE: Question about using global variables - Acies - 10-14-2011

The following part should be applied to the mapscript which contains the key:
void OnStart
{
SetEntityPlayerInteractCallback("The_Key_name", PickUpCatleena, true);
}

void PickUpCatleena(string &in asEntity)
{SetGlobalVarInt("HasKeyCatleena", 1);
}
[/code]

----------------------------------------------------------------------
Your original script with key:
Code:
void OnEnter()
{
    PlayMusic("25_amb.ogg", true, 1.0f, 10.0f, 1, true);
    AddEntityCollideCallback("Player", "keycheck", "keytrigger", false, 1);
}
void keytrigger(string &in asParent, string &in asChild, int alState)
{
        if (GetGlobalVarInt("HasKeyCatleena") == 1){
            SetEntityActive("tablechair_*", true);
            SetEntityActive("chairattable_*", false);
}else//If player doesn't have key - do stuff below
}


Information on variables:
  • Local variables only apply to the specific map - so if the key is in the same map as checked for this will be okay
  • Global variables apply to every map in your story
  • The default value of any variable is always 0
  • Int is integer values: 0, 1, 2, 3 and so forth
  • Float is values with decimals 1.3, 1.45, and so forth

Think of the variable as 0 = false | 1 = true
in the case of checking wheter a puzzle is complete or an item has been picked up.






RE: Question about using global variables - ggstarfoxxie - 10-14-2011

Thanks for your replies! I fixed the single equals to double equals & used the global functions & it works now, hurray! Big Grin