Frictional Games Forum (read-only)

Full Version: Variables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi
I need a fast and short tutorial about Variables.
Because I don't know what the variables are for. Big Grin
But I need to know it
I've already seen the tutorial on the Wiki.
But I don't really get it. (Because my english isn't good)
Variables are a way to store information. Then, later, you can use that information to assert what will happen in-game via script.
What do you mean with informations?
Could you make an example please?
Okay let's make an example.
First of all we will make a local variable called "EX".
The variable's default value, that is set by us at first will be 0, and then, after the player enters an area called "AREA", the function "FUNC" will be called, and the variable will be changed to any other value.

void OnEnter()
{
SetLocalVarInt("EX", 0); // 0 is the value we're giving to the var at first.
AddEntityCollideCallback("Player", "AREA", "FUNC", true, 1); //The area
}

Now we want to change the value of the variable if something happens, and then check it's value to do other things, example:

void FUNC(string &in asEntity, int alState)
{
AddLocalVarInt("EX", 1); //Adding '1' to the variable's value.
}


Now we want to check the variable's value, and do something if it equals 1, else we'll do something else.


void AnyOtherFunctionYouHave()
{
if(GetLocalVarInt("EX") == 1)
{
GiveSanityDamage(1.0f, true);
}
else
{
GiveSanityDamage(1.5f, true);
}
}


Okay, so what we did is, we've set an area in which the player will enter to, will set the variables "EX" value to '1' and then we checked in AnyOtherFunctionYouHave the variable's value, if it equals 1, the player will get 1 damage of sanity, else he will get 1.5 damage of sanity.

Thank you
O thinl I get it I'll test it soon