Some Papyrus questions

Post » Tue Nov 20, 2012 8:41 am

I have a script which is "hidden", does not extend anything, and contains several "global" functions, obviously so I can re-use them in multiple other scripts. But I'm a little unclear on some things here.

When I call these from my other scripts, they're not actually calling an instance of the 'hidden" script, right? Because it would seem that there never really is one, and instead, maybe the compiler just automatically includes the functions of it in any script that calls them? If that's true, I guess that also explains why it's not possible (or is useless) to have variables or properties in a script like that.

Also if it's true that it just gets included in other scripts when they're compiled, would it be possible to do something with a similar purpose with a "dummy object"? As in... I move the functions to an activator's script or something, and create an instance of that object, and then other objects can get and set its properties and call functions from it, etc? Because that would be very useful...

If I'm mistaken and the script is actually initalized as one object instead of being baked into the calling scripts by the compiler, can someone explain how it works instead, and could I declare variables in it in that case?

Thanks.
User avatar
Ella Loapaga
 
Posts: 3376
Joined: Fri Mar 09, 2007 2:45 pm

Post » Tue Nov 20, 2012 7:46 am

Hello. Global functions are not included and they're not ran on any instance. However, global functions share a common lock but I am unaware of whether all scripts share the same global lock or whether there is one global lock per script.
Note that the "import" keyword is just syntactic sugar and not change anything to everything I just wrote.

Also, a global function can only manipulate what you provide as parameters, and call other global methods. You cannot have global variables or properties. So, to achieve what you want, you actually need a dummy object with instance methods. Then you will provide this dummy object's unique instance to every script that needs to manipulate it.
User avatar
Amy Cooper
 
Posts: 3400
Joined: Thu Feb 01, 2007 2:38 am

Post » Tue Nov 20, 2012 4:26 am

Note that the "import" keyword is just syntactic sugar and not change anything to everything I just wrote.
Yeah, maybe I should have just looked at a pex file and answered that question on my own...

Also, a global function can only manipulate what you provide as parameters, and call other global methods. You cannot have global variables or properties. So, to achieve what you want, you actually need a dummy object with instance methods. Then you will provide this dummy object's unique instance to every script that needs to manipulate it.
Alright, thanks.
User avatar
Christine Pane
 
Posts: 3306
Joined: Mon Apr 23, 2007 2:14 am


Return to V - Skyrim