Jump to content

[LE] Experienced scripter opinion/knowledge required.


Recommended Posts

I've finished the mod and i'm in the process of preparing the mod's page and doing a few "Extra Checks" (just to be 110% sure).

In one of those checks i compare one of my 'Teleport' scripts to the vanilla 'DefaultTeleportAbility' Script and i noticed this.


The vanilla script is going 'Sub' by calling an 'Event' and mine is calling a 'Function', i've searched all weekend and couldn't find any info on this.

I did some tests and couldn't find any difference between the 2 (mainly execution time), so i wonder if there is any?.

Vanilla script:

Event OnHit(......)

If (........)

Teleport()

EndIf

EndEvent


Event Teleport()

If (....)

EndIf

EndEvent



My script:

Event OnHit(......)

If (........)

Teleport()

EndIf

EndEvent


Function Teleport()

If (....)

EndIf

EndFunction



Thank you very much for your time.

Link to comment
Share on other sites

For your purposes there shouldn't be any differences.

 

I do realize that the 'Event' can be used as 'GoSub > Function', but from your reply i'm guessing that this particular "Calling > GoSub" can have other applications.
If it's not too much trouble... could you provide a simple example? no need to go into deep details, from just one example i can understand.
* I'm a self teach scripter and some more specialised things I don't own them, especially since i haven't run into a script with this kind of logic to study.
Thank you very much in advance.
Link to comment
Share on other sites

The distinction between Event and Function is for the programmer. It's to distinguish stuff that's generated by some triggering 'event' from stuff that isn't (which is a bit of a squishy line, in practice). Most events are tied to the game engine throwing them, but custom events can be created that are thrown by a script, for whatever reason. So it has some applicability if you're doing X extends Y stuff (even for yourself) or if you're providing a framework for others. SkyUI has some good examples of this, with a lot of custom UI events for managing MCM work.

 

As far as the actual papyrus scripting engine is concerned though? They perform identically and can be treated identically in all respects.

Link to comment
Share on other sites

Functions and Events are exactly the same. the naming convention is for the human factor........

 

So a human being knows what is an Event and what a Function. So name thingys in coding is convention and design solely to make it easier for human beings to distinguish thingys, that confuse easily confuse them.

 

Compiler is smarter than human beings and shouldn't even be mention here. Cause it as nothing to with this, it is all about the human factor. Don't make more complicated than than with "'Event' can be used as 'GoSub > Function'," that got nothing to do with it.

 

edit:

BTW I tried to make it funny... it all about the guy reading the code, rename your Function to Event for the next guy who read it, Ok? There rules in coding... they are not the same to human beings.

 

if you want to know more google naming convention you will find that papyrus swings both ways, you can write it like python, or you and write it like C# or Java. The trick is stick to one convention so you don't confuse the reader. If you have a complicated validation you need to use a C# or Java convention. And since Papyrus is loose and a crappy example of a programming language. You can use a hybrid of both. In my experience most skyrim coder used the hybrid, cause we are lazy. and try to keep it simple where possible and skyrim compiler is very forgiving.

 

Functions and Events is the just tip of the iceberg.

Link to comment
Share on other sites

Hey glad you're about done. (Sub)routine and Functions are almost the same thing. The only real difference is a Function can return data or a value. A Sub can not. Your 1st choice should always be a Sub unless you you wish to return a value. Many programmer don't really follow this rule and just use Functions all the time (like me). But when I clean up my code at the end I will switch them to Subs if I ended up not using it to return any data. Well most the time ...

This was a big deal in the past as Subroutine were a bit faster and Functions were used for some type of math calculation you needed to return a value. Over time the speed of processors became so fast this is hardly noticeable. Programmers started using Functions for everything and newer programmers are not ever really told the difference. The fact is you are using a Gosub style of programing when using Subs and Functions vs a Goto style. So the very fact you are using them means you are using a higher form or style. Gosub style or "Function style" is basically the norm now. They no longer even teach the Goto style at all. Also known as "spaghetti code". There used to be a huge debate over the use of Gosub vs Goto. As you see Gosub won out due to a more understandable code and a more defined way of coding. This later turned into Subs and Functions. Here is the ironic part ... From an Assembler point of view all of this is just two Goto's. So even though many programmers will tell you to never use a Goto they are in fact using them all the time.

You could say why even have a Goto ... The answer is: It's actually used by the Gosub at compile time.

This is the same case with the Subroutine and the Function. Both are refined versions of the former but still use the former. In fact they are all refined versions of the Goto command from an Assembler point of view.

Short answer: Functions have a built in way to return a value. A Subroutine does not.

Edited by NexusComa2
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...