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
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


Messages In This Thread
Making your own functions - by Theforgot3n1 - 06-21-2013, 03:47 PM
RE: Making your own functions - by lizardrock17 - 06-21-2013, 04:02 PM
RE: Making your own functions - by DeAngelo - 06-21-2013, 04:30 PM
RE: Making your own functions - by richm0nkey - 06-27-2013, 07:28 AM
RE: Making your own functions - by ClayPigeon - 06-21-2013, 04:57 PM
RE: Making your own functions - by Theforgot3n1 - 06-21-2013, 05:08 PM
RE: Making your own functions - by Adrianis - 06-21-2013, 05:43 PM
RE: Making your own functions - by Bridge - 06-21-2013, 05:49 PM
RE: Making your own functions - by Adrianis - 06-21-2013, 06:10 PM
RE: Making your own functions - by Bridge - 06-21-2013, 06:26 PM
RE: Making your own functions - by Adrianis - 06-21-2013, 06:42 PM
RE: Making your own functions - by Bridge - 06-21-2013, 07:26 PM



Users browsing this thread: 1 Guest(s)