Emiel97 
 
 
		
			Junior Member 
			
			
			
 
			
	Posts: 4 
	Threads: 2 
	Joined: Mar 2015
	
 Reputation: 
0
		
	 | 
	
		
			
Question about basic scripting. 
			 
			
				Need help with something, how do i combine code? 
 
I want  the following two scipts/codes in the same .hps file: 
 
 
void OnStart() 
{    
   GiveItemFromFile("lantern", "lantern.ent"); 
  
   for(int i=0;i< 10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");     
} 
 
 
void OnStart() 
 
{   
  AddUseItemCallback("", "key_1", "locked_door1", "UsedKeyOnDoor", true); 
  SetEntityCallbackFunc("key_1", "OnPickup"); 
} 
void UsedKeyOnDoor(string &in asItem, string &in asEntity) 
{ 
  SetSwingDoorLocked("locked_door1", false, true); 
  PlaySoundAtEntity("", "unlock_door.snt", "locked_door1", 0, false); 
  RemoveItem("key_1"); 
} 
void OnPickup(string &in asEntity, string &in type) 
{ 
  SetEntityActive("monster_brute", true); 
  ShowEnemyPlayerPosition("monster_brute"); 
} 
 
 
I tried multiple things, watched multiple tutorials and browsed multiple topics, but still couldn't find what i was looking for! 
 
Help IS appreciated. Thanks!
			 
			
			
			
		 |  
	 
 | 
 
	| 03-11-2015, 08:56 PM  | 
	
		
	 | 
 
 
	
		
		FlawlessHappiness 
 
 
		
			Posting Freak 
			
			
			
 
			
	Posts: 3,980 
	Threads: 145 
	Joined: Mar 2012
	
 Reputation: 
171
		
	 | 
	
		
			
RE: Question about basic scripting. 
			 
			
				Well you see. There can't be 2 functions called "OnStart". 
So what you have to do with the void OnStart() is to combine them. 
Like this:
 void OnStart() {  GiveItemFromFile("lantern", "lantern.ent"); for(int i=0;i< 10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent"); 
  AddUseItemCallback("", "key_1", "locked_door1", "UsedKeyOnDoor", true); SetEntityCallbackFunc("key_1", "OnPickup"); } 
 
 
Makes sense, hmm?
 
Always remember: There cannot be 2 functions with the same name.
 
I've only skimmed over the other functions, as the OnStart seemed the most obvious. 
Try it out, and see if it works.
 
If it doesn't, please return here, and explain what happens.
 
If you get an error, show it to us. 
If you get something else, show it.
			  
			
			
 
Trying is the first step to success. 
			
		 |  
	 
 | 
 
	| 03-11-2015, 09:02 PM  | 
	
		
	 | 
 
 
	
		
		Emiel97 
 
 
		
			Junior Member 
			
			
			
 
			
	Posts: 4 
	Threads: 2 
	Joined: Mar 2015
	
 Reputation: 
0
		
	 | 
	
		
			
RE: Question about basic scripting. 
			 
			
				 (03-11-2015, 09:02 PM)FlawlessHappiness Wrote:  Well you see. There can't be 2 functions called "OnStart". 
 
So what you have to do with the void OnStart() is to combine them. 
Like this: 
 
void OnStart() {  GiveItemFromFile("lantern", "lantern.ent"); for(int i=0;i< 10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent"); 
  AddUseItemCallback("", "key_1", "locked_door1", "UsedKeyOnDoor", true); SetEntityCallbackFunc("key_1", "OnPickup"); } 
 
  
Makes sense, hmm? 
 
Always remember: There cannot be 2 functions with the same name. 
 
I've only skimmed over the other functions, as the OnStart seemed the most obvious. 
Try it out, and see if it works. 
 
If it doesn't, please return here, and explain what happens. 
 
If you get an error, show it to us. 
If you get something else, show it.  
 
Hey, 
 
The game doesn't crash, but it also doesn't fully work. What's supposed to happen is:  
 
1: When player starts the map, he will start with a Lantern and 10 Tinderboxes (works). 
 
2: When player picks up a key, a Monster spawns (doesn't work). 
 
EDIT: The "Monster spawn" script works when i start the document with that code. But then "1" won't do anything anymore (still no crash, gets completely ignored).
			  
			
			
			
				
(This post was last modified: 03-11-2015, 09:47 PM by Emiel97.)
 
				
			 
		 |  
	 
 | 
 
	| 03-11-2015, 09:42 PM  | 
	
		
	 | 
 
 
	
		
		FlawlessHappiness 
 
 
		
			Posting Freak 
			
			
			
 
			
	Posts: 3,980 
	Threads: 145 
	Joined: Mar 2012
	
 Reputation: 
171
		
	 | 
	
		
			
RE: Question about basic scripting. 
			 
			
				Well they don't work, because you have split the callbacks in 2 different void OnStart() 
The script is supposed to look like this:
 void OnStart() {  GiveItemFromFile("lantern", "lantern.ent");
  for(int i=0;i< 10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
  AddUseItemCallback("", "key_1", "locked_door1", "UsedKeyOnDoor", true); SetEntityCallbackFunc("key_1", "OnPickup"); }
 
  void UsedKeyOnDoor(string &in asItem, string &in asEntity) { SetSwingDoorLocked("locked_door1", false, true); PlaySoundAtEntity("", "unlock_door.snt", "locked_door1", 0, false); RemoveItem("key_1"); }
  void OnPickup(string &in asEntity, string &in type) { SetEntityActive("monster_brute", true); ShowEnemyPlayerPosition("monster_brute"); } 
 
 
Notice that there is only 1 "void OnStart()"
			  
			
			
 
Trying is the first step to success. 
			
		 |  
	 
 | 
 
	| 03-11-2015, 10:12 PM  | 
	
		
	 | 
 
 
	
		
		Emiel97 
 
 
		
			Junior Member 
			
			
			
 
			
	Posts: 4 
	Threads: 2 
	Joined: Mar 2015
	
 Reputation: 
0
		
	 | 
	
		
			
RE: Question about basic scripting. 
			 
			
				They both work now, thank you very much! 
 
I see what i did wrong. Now just going to play around with some more code and see how it goes. 
 
 
Thanks!
			 
			
			
			
		 |  
	 
 | 
 
	| 03-11-2015, 10:22 PM  | 
	
		
	 | 
 
 
	
		
		FlawlessHappiness 
 
 
		
			Posting Freak 
			
			
			
 
			
	Posts: 3,980 
	Threads: 145 
	Joined: Mar 2012
	
 Reputation: 
171
		
	 | 
	
		
			
RE: Question about basic scripting. 
			 
			
				I'm glad it works! 
 
Feel free to ask more questions.
			 
			
			
 
Trying is the first step to success. 
			
		 |  
	 
 | 
 
	| 03-11-2015, 11:15 PM  | 
	
		
	 | 
 
 
	 
 |