Calling a function vs Creating a function

Post » Fri Nov 16, 2012 4:19 pm

Hey guys, I'd have posted this in the Quick Questions thread, but wasn't sure how quick the answer would be haha.

I'm learning scripting and things, and actually going through the official tutorials to learn the WHY's, as so far I've just been using/making basic scripts. I'm referring to this tutorial - http://www.creationkit.com/Bethesda_Tutorial_Papyrus_Introduction_to_Properties

I've done the Calling Functions on Properties. Works great, different message each time, etc etc. Now the next section, Creating function, seems to achieve the exact same results as calling a function... so why bother? Why would you choose to call a function over creating one, or vice versa? Am I becoming overly confused, is it basically just different ways to achieve the same thing? Or are there real benefits and pitfalls to the different methods?
User avatar
Dina Boudreau
 
Posts: 3410
Joined: Thu Jan 04, 2007 10:59 pm

Post » Fri Nov 16, 2012 2:01 pm

If you create your own functions you can bundle up chunks of code you use a lot and put them into one function and then call that.

They're a bit like batch files, sort of. You set up a useful set of operations and bundle them together so you can call them as a unit over and over.

Plus you get to pass parameters and vary the data they run on.
User avatar
Matthew Barrows
 
Posts: 3388
Joined: Thu Jun 28, 2007 11:24 pm

Post » Fri Nov 16, 2012 9:56 pm

Ok thanks mate I think I understand. So basically for that tutorial, for what they wanted to achieve creating a function is unnecessary. But creating your own allows for more "batch" coding? :)
User avatar
Britta Gronkowski
 
Posts: 3475
Joined: Mon Apr 09, 2007 3:14 pm

Post » Fri Nov 16, 2012 6:23 pm

As DocClox says, functions are a way of grouping your code. Usually I make functions for two reasons:
1) make code more managable - rather than having one big "function", I break the code out in to smaller, more manageable chunks
2) make reusing code easier - since I make the function to accomplish a specific purpose, I can call that same function from another place in my code

And one other benifit to functions - is calling Other peoples functions. In this case, the built in functions provided by Bethesda (and possibly SKSE). Loo at all that code "resuse"! ;)
User avatar
Stacy Hope
 
Posts: 3391
Joined: Thu Jun 22, 2006 6:23 am

Post » Fri Nov 16, 2012 6:23 pm

Arguments in your functions behave just like variables/properties, but will always default to their defined values wiping the slate clean for the next use. If an argument is necessary for the function to work, it needn't be set while if you have optional arguments, you'll want to set them to None/""/0/False that you won't have to necessarily use them to get your function to work. It's best to put the crucial arguments first, then define the ones less likely to need setting when calling the function.

Note that all the official arguments have a relatively standardized nomenclature, prefixing the argument names with their types. It's a good idea to do so with your own functions as it makes it easy to tell what you're working with.

a : Argument :: b : Bool :: f : Float :: i : Int :: k : Form :: r : Reference :: s : String :: u : Unsigned

Anyhow, I'm really liking that we can create our own functions so readily. Papyrus puts the 'fun' in function! :)
User avatar
Rudi Carter
 
Posts: 3365
Joined: Fri Sep 01, 2006 11:09 pm

Post » Fri Nov 16, 2012 2:50 pm

Ok thanks for the posts guys :) a lot of the terminology goes over my head, I get the basic idea though.
User avatar
Crystal Birch
 
Posts: 3416
Joined: Sat Mar 03, 2007 3:34 pm


Return to V - Skyrim