Frictional Games Forum (read-only)

Full Version: If All Candles Inactive, Fade To Black Script?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello, again!

Is there a script so that if, for example, there are three candles in a room. To blow them out the player must collide with the script area surrounding that candle. Basically, when the player collides with the area it renders the candle inactive. Is there a way so that once all candles are inactive the screen fades to black? Like this:

Walks over to Candle 1 Area - Blows the candle out
Candle2&3 still active, so no Fade To Black

Walks over to Candle 2 Area - Blows the candle out
Candle3 still active, so no Fade To Black

Walks over to Candle 3 Area - Blows the candle out
All candles inactive, fade to black occurs

Also, would it matter if the player did blew the candles out in a random order?
Yes, here it is:

Code:
void OnStart()
{
AddEntityCollideCallback("script_area1", "Player", "Func1", true, 0);
AddEntityCollideCallback("script_area2", "Player", "Func2", true, 0);
AddEntityCollideCallback("script_area3", "Player", "Func3", true, 0);
SetLocalVarInt("lamplit", 0);
}

void Func1(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle1", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func2(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle2", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func3(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle3", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void check()
{
if(GetLocalVarInt("lamplit")===3)
{
FadeOut(2);
}
else
{

}
}
Everytime the players unlits a candle, the function 'check' goes active. The function 'check' checks if the variable 'lamplit' is 3. If it's not, it does nothing.Ugh, my english..
(05-04-2013, 12:52 PM)Smoke Wrote: [ -> ]Yes, here it is:

Code:
void OnStart()
{
AddEntityCollideCallback("script_area1", "Player", "Func1", true, 0);
AddEntityCollideCallback("script_area2", "Player", "Func2", true, 0);
AddEntityCollideCallback("script_area3", "Player", "Func3", true, 0);
SetLocalVarInt("lamplit", 0);
}

void Func1(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle1", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func2(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle2", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func3(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle3", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void check()
{
if(GetLocalVarInt("lamplit")===3)
{
FadeOut(2);
}
else
{

}
}
Everytime the players unlits a candle, the function 'check' goes active. The function 'check' checks if the variable 'lamplit' is 3. If it's not, it does nothing.Ugh, my english..


Okay, I understand most of that, but why would "lamplit" equal to three when you set the varients to zero? Does that mean if the three "lamplit" items all equal the same fade out?
No, I just added a variable in OnStart() with the number 0. Everytime he collides with the script_area, the AddLocalVarInt adds 1 on top of that. So first time 0 + 1 = 1. So after the player unlits the first candle, the lamplit variable = 1. Same with the second and third candle. You can check this with if(GetLocalVarInt("lamplit")===1) and if(GetLocalVarInt("lamplit")===2). And letting them play a sound or something in brackets.

This script would do the same:

Code:
void OnStart()
{
AddEntityCollideCallback("script_area1", "Player", "Func1", true, 0);
AddEntityCollideCallback("script_area2", "Player", "Func2", true, 0);
AddEntityCollideCallback("script_area3", "Player", "Func3", true, 0);
SetLocalVarInt("lamplit", 5);
}

void Func1(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle1", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func2(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle2", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func3(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle3", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void check()
{
if(GetLocalVarInt("lamplit")===8)
{
FadeOut(2);
}
else
{

}
}

It's just easier to start with 0 instead of 5.
(05-04-2013, 01:01 PM)Smoke Wrote: [ -> ]No, I just added a variable in OnStart() with the number 0. Everytime he collides with the script_area, the AddLocalVarInt adds 1 on top of that. So first time 0 + 1 = 1. So after the player unlits the first candle, the lamplit variable = 1. Same with the second and third candle.

You can check this with if(GetLocalVarInt("lamplit")===1) and if(GetLocalVarInt("lamplit")===2). And letting them play a sound or something in brackets.

Ah! I get it now. Thank you, this is perfect!
No problem Wink
(05-04-2013, 01:06 PM)Smoke Wrote: [ -> ]No problem Wink

To add another candle, would I just have to add another script area, another function and set the "=== 3" to "=== 4"?
(05-04-2013, 12:52 PM)Smoke Wrote: [ -> ]Yes, here it is:

Code:
void OnStart()
{
AddEntityCollideCallback("script_area1", "Player", "Func1", true, 0);
AddEntityCollideCallback("script_area2", "Player", "Func2", true, 0);
AddEntityCollideCallback("script_area3", "Player", "Func3", true, 0);
SetLocalVarInt("lamplit", 0);
}

void Func1(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle1", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func2(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle2", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func3(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle3", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void check()
{
if(GetLocalVarInt("lamplit")===3)
{
FadeOut(2);
}
else
{

}
}
Everytime the players unlits a candle, the function 'check' goes active. The function 'check' checks if the variable 'lamplit' is 3. If it's not, it does nothing.Ugh, my english..

Im curious, whats the difference between using 2 is equal to signs and using 3, to be more specific whats the difference between "==" and "==="
(05-04-2013, 02:05 PM)martinnord Wrote: [ -> ]
(05-04-2013, 12:52 PM)Smoke Wrote: [ -> ]Yes, here it is:

Code:
void OnStart()
{
AddEntityCollideCallback("script_area1", "Player", "Func1", true, 0);
AddEntityCollideCallback("script_area2", "Player", "Func2", true, 0);
AddEntityCollideCallback("script_area3", "Player", "Func3", true, 0);
SetLocalVarInt("lamplit", 0);
}

void Func1(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle1", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func2(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle2", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void Func3(string &in asParent, string &in asChild, int alState)
{
SetLampLit("candle3", false, true);
AddLocalVarInt("lamplit", 1);
check();
}

void check()
{
if(GetLocalVarInt("lamplit")===3)
{
FadeOut(2);
}
else
{

}
}
Everytime the players unlits a candle, the function 'check' goes active. The function 'check' checks if the variable 'lamplit' is 3. If it's not, it does nothing.Ugh, my english..

Im curious, whats the difference between using 2 is equal to signs and using 3, to be more specific whats the difference between "==" and "==="

Me too. This isn't in the comparison operators.
(05-04-2013, 01:06 PM)Smoke Wrote: [ -> ]No problem Wink

Doesn't seem to be working. I keep getting fatal errors
Pages: 1 2