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
Question about using global variables
ggstarfoxxie Offline
Junior Member

Posts: 36
Threads: 9
Joined: Aug 2011
Reputation: 2
#1
Question  Question about using global variables

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.

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

(This post was last modified: 10-14-2011, 01:45 AM by ggstarfoxxie.)
10-14-2011, 12:33 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#2
RE: Question about using global variables

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.

Tutorials: From Noob to Pro
(This post was last modified: 10-14-2011, 12:48 AM by Your Computer.)
10-14-2011, 12:47 AM
Website Find
Acies Offline
Posting Freak

Posts: 1,643
Threads: 60
Joined: Feb 2011
Reputation: 73
#3
RE: Question about using global variables

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:
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.




[Image: mZiYnxe.png]


(This post was last modified: 10-14-2011, 12:50 AM by Acies.)
10-14-2011, 12:49 AM
Find
ggstarfoxxie Offline
Junior Member

Posts: 36
Threads: 9
Joined: Aug 2011
Reputation: 2
#4
RE: Question about using global variables

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

10-14-2011, 01:42 AM
Find




Users browsing this thread: 1 Guest(s)