Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making your own functions
Theforgot3n1 Offline
Member

Posts: 192
Threads: 20
Joined: Apr 2012
Reputation: 6
#1
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. Smile

Confusion: a Custom Story - Ch1 for play!
http://www.frictionalgames.com/forum/thread-15477.html
About 50% built.
Delayed for now though!
06-21-2013, 03:47 PM
Website Find
lizardrock17 Offline
Junior Member

Posts: 20
Threads: 3
Joined: Jun 2013
Reputation: 0
#2
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
Find
DeAngelo Offline
Senior Member

Posts: 263
Threads: 26
Joined: Feb 2013
Reputation: 11
#3
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);

A Late Night Drink http://www.moddb.com/mods/a-late-night-drink
Check out my LP channel, CatBearGaming, I take all Custom Story requests!
06-21-2013, 04:30 PM
Find
ClayPigeon Offline
Member

Posts: 214
Threads: 13
Joined: Mar 2012
Reputation: 8
#4
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:
MyFunc(2);
And the function will perform.
06-21-2013, 04:57 PM
Find
Theforgot3n1 Offline
Member

Posts: 192
Threads: 20
Joined: Apr 2012
Reputation: 6
#5
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. Smile

Confusion: a Custom Story - Ch1 for play!
http://www.frictionalgames.com/forum/thread-15477.html
About 50% built.
Delayed for now though!
(This post was last modified: 06-21-2013, 05:11 PM by Theforgot3n1.)
06-21-2013, 05:08 PM
Website Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#6
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
Find
Bridge Offline
Posting Freak

Posts: 1,971
Threads: 25
Joined: May 2012
Reputation: 128
#7
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
Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#8
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 Tongue

Defining your own functions can be incredibly useful but it is very rarely necessary

06-21-2013, 06:10 PM
Find
Bridge Offline
Posting Freak

Posts: 1,971
Threads: 25
Joined: May 2012
Reputation: 128
#9
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 Tongue

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
Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#10
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
Find




Users browsing this thread: 1 Guest(s)