| 
		
	
		| AGP   Senior Member
 
 Posts: 448
 Threads: 45
 Joined: Dec 2012
 Reputation: 
23
 | 
			| Using a Timer to Unlock a Door 
 
				All right, I've been searching around for a code to unlock a door after a certain amount of time, but not really found what I was looking for.
 Any ideas?
 
 |  |  
	| 05-06-2013, 05:13 PM |  |  
	
		| Tomato Cat   Senior Member
 
 Posts: 287
 Threads: 2
 Joined: Sep 2012
 Reputation: 
20
 | 
			| RE: Using a Timer to Unlock a Door 
 
				First, you would need something to trigger the timer. Collide, useitem, etc etc. When the timer expires, its callback would call the SetSwingDoorLocked function. 
Also, I would visit the wiki . It has documentation for each function.
			
				
(This post was last modified: 05-06-2013, 05:25 PM by Tomato Cat.)
 |  |  
	| 05-06-2013, 05:22 PM |  |  
	
		| AGP   Senior Member
 
 Posts: 448
 Threads: 45
 Joined: Dec 2012
 Reputation: 
23
 | 
			| RE: Using a Timer to Unlock a Door 
 
				Sounds good, but still very confused with the script for the timer. 
This is what the wiki says, but no idea what it means. Still pretty new to scripting.
 void AddTimer(string& asName, float afTime, string& asFunction);
 
 Creates a timer which calls a function when it expires.
 
 
 Callback syntax: void MyFunc(string &in asTimer)
 
 
 
 asName - the name of the timer
 
 
 afTime - time in seconds
 
 
 asFunction - the function to call
 |  |  
	| 05-06-2013, 05:36 PM |  |  
	
		| Tomato Cat   Senior Member
 
 Posts: 287
 Threads: 2
 Joined: Sep 2012
 Reputation: 
20
 | 
			| RE: Using a Timer to Unlock a Door 
 
				asName, afTime, and asFunction are known as arguments. 
asName is the name of your timer. Basically a string. It isn't required (unless you wish to use stop timer), but I recommend it as it can help you keep track of multiple timers. 
 
afTime is, well, the time. "Float" is basically a decimal number. As an example, 1.5f will create a timer that runs for 1.5 seconds.
 
asFunction is the callback. This is the function that will be called when your timer expires. 
 
asTimer is the parameter for the callback function. 
 
Here's an example.
 void Function()//Parameters would go here, depending on what called this function{
 //This function starts the timer
 AddTimer("ExampleTimer",1.5f,"TimerCall");
 //Name of timer, the time, and the callback
 }
 
 void TimerCall(string &in asTimer) //This function is called when the timer expires
 {
 //Do things here
 }
 
				
(This post was last modified: 05-06-2013, 06:00 PM by Tomato Cat.)
 |  |  
	| 05-06-2013, 05:59 PM |  |  
	
		| AGP   Senior Member
 
 Posts: 448
 Threads: 45
 Joined: Dec 2012
 Reputation: 
23
 | 
			| RE: Using a Timer to Unlock a Door 
 
				Okay, so the player hits a script area named "timer_area" and then after 42 seconds, the door named "hall_door" would unlock. The door is already set to locked in the editor. 
This script probably looks like the world's biggest mess....
 In OnStart(){
 AddEntityCollideCallback("Player", "timer_area", "OpenDoor", true, -1);
 }
 
 void OpenDoor()
 {
 AddTimer("ExampleTimer",42f,"TimerCall");
 }
 
 void TimerCall(string &in asTimer)
 {
 SetSwingDoorClosed("hall_door", false, true);
 }
 |  |  
	| 05-06-2013, 06:13 PM |  |  
	
		| Tomato Cat   Senior Member
 
 Posts: 287
 Threads: 2
 Joined: Sep 2012
 Reputation: 
20
 | 
			| RE: Using a Timer to Unlock a Door 
 
				Looks good, but you're missing the parameters for OpenDoor. 
Same kind of deal with the timer. Except the entitycollide has a different callback syntax:
 void Function(string &in asParent, string &in asChild, int alState) 
				
(This post was last modified: 05-06-2013, 06:17 PM by Tomato Cat.)
 |  |  
	| 05-06-2013, 06:17 PM |  |  
	
		| AGP   Senior Member
 
 Posts: 448
 Threads: 45
 Joined: Dec 2012
 Reputation: 
23
 | 
			| RE: Using a Timer to Unlock a Door 
 
				Now getting a error saying " f is not declared".
			 
 |  |  
	| 05-06-2013, 06:27 PM |  |  
	
		| Tomato Cat   Senior Member
 
 Posts: 287
 Threads: 2
 Joined: Sep 2012
 Reputation: 
20
 | 
			| RE: Using a Timer to Unlock a Door 
 
				Try changing it to 42.0f? 
Oh, and is "In" in your .hps file?
 In OnStart(){
 AddEntityCollideCallback("Player", "timer_area", "OpenDoor", true, -1);
 }
 
				
(This post was last modified: 05-06-2013, 06:28 PM by Tomato Cat.)
 |  |  
	| 05-06-2013, 06:27 PM |  |  
	
		| AGP   Senior Member
 
 Posts: 448
 Threads: 45
 Joined: Dec 2012
 Reputation: 
23
 | 
			| RE: Using a Timer to Unlock a Door 
 
				Error is gone. Yippee, but the door is not opening. =/ void OpenDoor(string &in asParent, string &in asChild, int alState) {
 AddTimer("ExampleTimer", 42.0f, "TimerCall");
 }
 
 void TimerCall(string &in asTimer)
 {
 SetSwingDoorClosed("hall_door", false, true);
 }
 |  |  
	| 05-06-2013, 06:32 PM |  |  
	
		| Tomato Cat   Senior Member
 
 Posts: 287
 Threads: 2
 Joined: Sep 2012
 Reputation: 
20
 | 
			| RE: Using a Timer to Unlock a Door 
 
				Try SetSwingDoorLocked.
			 |  |  
	| 05-06-2013, 06:45 PM |  |  |