| 
		
	
		| mccrazy5   Junior Member
 
 Posts: 11
 Threads: 4
 Joined: Jun 2012
 Reputation: 
0
 | 
			|  about scripting 
 
				Hello guys , i am trying to script a key to open a door.I have looked for some tutorials and i found some.
 But when i tried them, It didnt work for me.
 This is what i did:
 I have made a small room with a door and a key .
 I have locked the door and named it "mansion_1".
 I made a key and on name i called it "key_1" and in the entity i have called it "key1"
 After that i have created this script.
 And when i run this on game, the game crash.
 ////////////////////////////
 // Run first time starting map
 void OnStart()
 {
 AddUseItemCallback("", "key1", "mansion_1", "KeyOnDoor", true);
 }
 
 void KeyOnDoor(string &in asItem, string &in asEntity)
 
 {
 SetSwingDoorLocked(asEntity, false, true);
 PlaySoundAtEntity("", "unlock_door", mansion_1, 0, false);
 RemoveItem(asItem);
 }
 
 
 ////////////////////////////
 // Run when entering map
 void OnEnter()
 {
 
 }
 
 ////////////////////////////
 // Run when leaving map
 void OnLeave()
 {
 
 }
 
 Any idea why its not working ?
 |  |  
	| 06-09-2012, 05:56 PM |  |  
	
		| Putmalk   Senior Member
 
 Posts: 290
 Threads: 13
 Joined: Apr 2012
 Reputation: 
15
 | 
			| RE: about scripting 
 
				PlaySoundAtEntity("", "unlock_door", mansion_1, 0, false);
 Should be quotations around mansion_1
 
 |  |  
	| 06-09-2012, 06:05 PM |  |  
	
		| mccrazy5   Junior Member
 
 Posts: 11
 Threads: 4
 Joined: Jun 2012
 Reputation: 
0
 | 
			| RE: about scripting 
 
				Alright, i added quotations to mansion1 . now the game dont crash but the key doesnt open the door.hmm ?
 |  |  
	| 06-09-2012, 06:36 PM |  |  
	
		| Science   Junior Member
 
 Posts: 9
 Threads: 0
 Joined: Jun 2012
 Reputation: 
0
 | 
			| RE: about scripting 
 
				SetSwingDoorLocked(asEntity, false, true); 
 
 RemoveItem(asItem);
 
 Declare these first.
 |  |  
	| 06-09-2012, 06:44 PM |  |  
	
		| Putmalk   Senior Member
 
 Posts: 290
 Threads: 13
 Joined: Apr 2012
 Reputation: 
15
 | 
			| RE: about scripting 
 
				 (06-09-2012, 06:44 PM)Science Wrote:  SetSwingDoorLocked(asEntity, false, true); 
 
 RemoveItem(asItem);
 
 Declare these first.
 They're already declared.
 
Double check your naming and removing all cache files for your map.
 
Other than that, I'll inspect closely later.
 Quote:Alright, i added quotations to mansion1 . now the game dont crash but the key doesnt open the door.hmm ?
 
Be more specific. Is it saying "Cannot use item in this way!" or just fails to open it?
			 
 
				
(This post was last modified: 06-09-2012, 07:03 PM by Putmalk.)
 |  |  
	| 06-09-2012, 06:54 PM |  |  
	
		| mccrazy5   Junior Member
 
 Posts: 11
 Threads: 4
 Joined: Jun 2012
 Reputation: 
0
 | 
			| RE: about scripting 
 
				 (06-09-2012, 06:54 PM)Putmalk Wrote:   (06-09-2012, 06:44 PM)Science Wrote:  SetSwingDoorLocked(asEntity, false, true); They're already declared.
 
 RemoveItem(asItem);
 
 Declare these first.
 
 Double check your naming and removing all cache files for your map.
 
 Other than that, I'll inspect closely later.
 
 
 Quote:Alright, i added quotations to mansion1 . now the game dont crash but the key doesnt open the door.hmm ?
 Be more specific. Is it saying "Cannot use item in this way!" or just fails to open it?
 Alright i removed the cache file from my map, and ii tried again. 
it says "Cannot use item in this way!" 
 
and i checked the names everything is match.
 
 
Edit: alright i found the problem ... in the script i used the name that i typed the key on the entity.. but i had to type in the script the name i just called it on general.. thanks guys for your help i fixed it    
				
(This post was last modified: 06-09-2012, 07:21 PM by mccrazy5.)
 |  |  
	| 06-09-2012, 07:12 PM |  |  |