| 
		
	
		| Theforgot3n1   Member
 
 Posts: 192
 Threads: 20
 Joined: Apr 2012
 Reputation: 
6
 | 
			| Making your own functions 
 
				Hello!  
This might be out of our league, but is there perhaps a way to create my own function? In my specific instance, I would like to remove a rope between a RopeArea and a PosNode. Is there perhaps a way to compose a function called for example "void RemoveRope(string& asName);"? 
 
Datz allz.   
 |  |  
	| 06-21-2013, 03:47 PM |  |  
	
		| lizardrock17   Junior Member
 
 Posts: 20
 Threads: 3
 Joined: Jun 2013
 Reputation: 
0
 | 
			| RE: Making your own functions 
 
				The scripts come with the HPL 2 engine so unless you edit the engine entirely you wont be able to create your own function. (very good question in fact so good im not even 100% sur this is correct)
			 
				
(This post was last modified: 06-21-2013, 04:02 PM by lizardrock17.)
 |  |  
	| 06-21-2013, 04:02 PM |  |  
	
		| DeAngelo   Senior Member
 
 Posts: 263
 Threads: 26
 Joined: Feb 2013
 Reputation: 
11
 | 
			| RE: Making your own functions 
 
				Lizard is right, though I've always wondered if there are any hidden functions the HPL is capable of that we don't know about because Frictional never used them. I assume the list we have is based on what was found in the script files that come with the game, so who knows. There might be some stray function out in the ether we'll never know of. Maybe it's
 void MakeGruntNotStupid(String& asAI)
 {
 SetGruntAILevel(10);
 }
 
 or maybe
 
 SetRandomlyFallThroughGroundIntoNothing(false);
 
 |  |  
	| 06-21-2013, 04:30 PM |  |  
	
		| ClayPigeon   Member
 
 Posts: 214
 Threads: 13
 Joined: Mar 2012
 Reputation: 
8
 | 
			| RE: Making your own functions 
 
				It depends whatever the function should return. (What is the value type) 
If the value type is an integer, you'd probably do:
 int myfunction(int val, float val2){     return someinteger;}
For a string, float or whatever else:
 string myfunction(string &in MyStr){    return somestring;}float myfloatfunction(float val){    return somefloat;}
However, if the function doesn't reutrn any value, but only does a few operations, you'd use void:
 void MyFunction(parameters){    something    something2}
And to use it whenever you need it:
 And the function will perform.
			 |  |  
	| 06-21-2013, 04:57 PM |  |  
	
		| Theforgot3n1   Member
 
 Posts: 192
 Threads: 20
 Joined: Apr 2012
 Reputation: 
6
 | 
			| RE: Making your own functions 
 
				My supposed function would be using a void probably. And DeAngelo, getting that grunt function would be a dream come true... 
But alright, I see whatcha gaiz mean. Thanks for the clarification.   
 
				
(This post was last modified: 06-21-2013, 05:11 PM by Theforgot3n1.)
 |  |  
	| 06-21-2013, 05:08 PM |  |  
	
		| Adrianis   Senior Member
 
 Posts: 620
 Threads: 6
 Joined: Feb 2012
 Reputation: 
27
 | 
			| RE: Making your own functions 
 
				You absolutely can create you're own functions, if you have a set of function calls you need to run regularly with minor alterations, it makes perfect sense. ClayPigeon's explanations shows how, although you might be wandering why and in what situations you would want to do that. Giving some examples for that would take time, but if you guys would find it useful I would be happy to do so
 You cannot, however, define new engine functions to control gameplay in the way you are probably hoping! The only control over the engine you have is through the functions available in the engine scripts page
 
 |  |  
	| 06-21-2013, 05:43 PM |  |  
	
		| Bridge   Posting Freak
 
 Posts: 1,971
 Threads: 25
 Joined: May 2012
 Reputation: 
128
 | 
			| RE: Making your own functions 
 
				 (06-21-2013, 05:43 PM)Adrianis Wrote:  You absolutely can create you're own functions, if you have a set of function calls you need to run regularly with minor alterations, it makes perfect sense. ClayPigeon's explanations shows how, although you might be wandering why and in what situations you would want to do that. Giving some examples for that would take time, but if you guys would find it useful I would be happy to do so
 You cannot, however, define new engine functions to control gameplay in the way you are probably hoping! The only control over the engine you have is through the functions available in the engine scripts page
 
You're referring to function overloading, right?
			 |  |  
	| 06-21-2013, 05:49 PM |  |  
	
		| Adrianis   Senior Member
 
 Posts: 620
 Threads: 6
 Joined: Feb 2012
 Reputation: 
27
 | 
			| RE: Making your own functions 
 
				 (06-21-2013, 05:49 PM)Bridge Wrote:  You're referring to function overloading, right? 
Not exclusively no, although that's one (probably more common) usage
 
Check out this post in this thread
http://www.frictionalgames.com/forum/thr...#pid193591 
That's the kind of thing you can do by defining your own functions, the code bit is what's relevant, much of the explanation was to do with the topic at hand which was to do with reference parameters, which no one really need to worry about    
Defining your own functions can be incredibly useful but it is very rarely necessary
			 
 |  |  
	| 06-21-2013, 06:10 PM |  |  
	
		| Bridge   Posting Freak
 
 Posts: 1,971
 Threads: 25
 Joined: May 2012
 Reputation: 
128
 | 
			| RE: Making your own functions 
 
				 (06-21-2013, 06:10 PM)Adrianis Wrote:   (06-21-2013, 05:49 PM)Bridge Wrote:  You're referring to function overloading, right? Not exclusively no, although that's one (probably more common) usage
 
 
 Check out this post in this thread
 http://www.frictionalgames.com/forum/thr...#pid193591
 
 That's the kind of thing you can do by defining your own functions, the code bit is what's relevant, much of the explanation was to do with the topic at hand which was to do with reference parameters, which no one really need to worry about
  
 Defining your own functions can be incredibly useful but it is very rarely necessary
 
I can't say in the case of Amnesia scripting because I don't actually do it but I don't think I've ever written a program without defining a single function. If a piece of code is repeated more than twice verbatim (or the only discrepancies are the values used) then defining a function for it is smart IMO. It saves a whole bunch of space (unless it's an inline function) and is much cleaner to read IMO.
 
Out of curiosity, why do you consider it to be rarely necessary in the case of Amnesia?
			 |  |  
	| 06-21-2013, 06:26 PM |  |  
	
		| Adrianis   Senior Member
 
 Posts: 620
 Threads: 6
 Joined: Feb 2012
 Reputation: 
27
 | 
			| RE: Making your own functions 
 
				 (06-21-2013, 06:26 PM)Bridge Wrote:  I can't say in the case of Amnesia scripting because I don't actually do it but I don't think I've ever written a program without defining a single function. If a piece of code is repeated more than twice verbatim (or the only discrepancies are the values used) then defining a function for it is smart IMO. It saves a whole bunch of space (unless it's an inline function) and is much cleaner to read IMO.
 Out of curiosity, why do you consider it to be rarely necessary in the case of Amnesia?
 
Of course functions have been the basis for every program since.. forever. It's more to do with the terminology we're using here - technically speaking there is absolutely nothing you can do in Amnesia scripts that doesn't involve writing functions, everything except global scope variable declarations has to take place within a function - the same as in C, where Main is a function, the only stuff you have outside of a function is pre-processor code & global vars
 
When you write 'void OnStart() {}' you have defined a function, but that is part of the HPL2 API. I think what these guys are talking about is writing your own function, outside of the HPL2 API. I also assumed that they were referring to functions you define other than the definitions for function callbacks when using AddTimer (for example)
 
So taking that into account, it is rarely necessary to write a whole new function that is not a callback or part of the API, particularly as Amnesia scripts are merely defining the logic of the map, which wouldn't often require much repetition.
 
On the other hand, working with a proper programming language like C, of course every function definition is entirely of you're own creation, you can only call to functions that are not defined by you (in header libraries). But this is a scripting language, and it's behaviors are defined by the script engine within HPL2, so you rarely need to define behaviors other than the ones already provided for you.
 
I hope that clears it up a little...
			 
 
				
(This post was last modified: 06-21-2013, 06:48 PM by Adrianis.)
 |  |  
	| 06-21-2013, 06:42 PM |  |  |