| 
		
	
		| FurtherGames   Member
 
 Posts: 72
 Threads: 23
 Joined: Apr 2013
 Reputation: 
1
 | 
			|  If All Candles Inactive, Fade To Black Script? 
 
				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?
 
				
(This post was last modified: 05-04-2013, 01:04 PM by FurtherGames.)
 |  |  
	| 05-04-2013, 12:43 PM |  |  
	
		| OriginalUsername   Posting Freak
 
 Posts: 896
 Threads: 42
 Joined: Feb 2013
 Reputation: 
34
 | 
			| RE: If All Candles Inactive, Fade To Black Script? 
 
				Yes, here it is: 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 |  |  
	
		| FurtherGames   Member
 
 Posts: 72
 Threads: 23
 Joined: Apr 2013
 Reputation: 
1
 | 
			| RE: If All Candles Inactive, Fade To Black Script? 
 
				 (05-04-2013, 12:52 PM)Smoke Wrote:  Yes, here it is:
 
 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..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
 {
 
 }
 }
 
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?
			 |  |  
	| 05-04-2013, 12:58 PM |  |  
	
		| OriginalUsername   Posting Freak
 
 Posts: 896
 Threads: 42
 Joined: Feb 2013
 Reputation: 
34
 | 
			| RE: If All Candles Inactive, Fade To Black Script? 
 
				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:
 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 |  |  
	
		| FurtherGames   Member
 
 Posts: 72
 Threads: 23
 Joined: Apr 2013
 Reputation: 
1
 | 
			| RE: If All Candles Inactive, Fade To Black Script? 
 
				 (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!
			 |  |  
	| 05-04-2013, 01:06 PM |  |  
	
		| OriginalUsername   Posting Freak
 
 Posts: 896
 Threads: 42
 Joined: Feb 2013
 Reputation: 
34
 | 
			| RE: If All Candles Inactive, Fade To Black Script? 
 
				No problem    |  |  
	| 05-04-2013, 01:06 PM |  |  
	
		| FurtherGames   Member
 
 Posts: 72
 Threads: 23
 Joined: Apr 2013
 Reputation: 
1
 | 
			| RE: If All Candles Inactive, Fade To Black Script? 
 
				 (05-04-2013, 01:06 PM)Smoke Wrote:  No problem  
To add another candle, would I just have to add another script area, another function and set the "=== 3" to "=== 4"?
			 |  |  
	| 05-04-2013, 01:41 PM |  |  
	
		| WALP   Posting Freak
 
 Posts: 1,221
 Threads: 34
 Joined: Aug 2012
 Reputation: 
45
 | 
			| RE: If All Candles Inactive, Fade To Black Script? 
 
				 (05-04-2013, 12:52 PM)Smoke Wrote:  Yes, here it is:
 
 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..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
 {
 
 }
 }
 
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 |  |  
	
		| PutraenusAlivius   Posting Freak
 
 Posts: 4,713
 Threads: 75
 Joined: Dec 2012
 Reputation: 
119
 | 
			| RE: If All Candles Inactive, Fade To Black Script? 
 
				 (05-04-2013, 02:05 PM)martinnord Wrote:   (05-04-2013, 12:52 PM)Smoke Wrote:  Yes, here it is:
 
 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..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
 {
 
 }
 }
 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.
			 
 "Veni, vidi, vici.""I came, I saw, I conquered."
 |  |  
	| 05-04-2013, 02:07 PM |  |  
	
		| FurtherGames   Member
 
 Posts: 72
 Threads: 23
 Joined: Apr 2013
 Reputation: 
1
 | 
			| RE: If All Candles Inactive, Fade To Black Script? 
 
				 (05-04-2013, 01:06 PM)Smoke Wrote:  No problem  
Doesn't seem to be working. I keep getting fatal errors
			 |  |  
	| 05-04-2013, 03:52 PM |  |  |