Best way to create a "global" script?

Post » Sat Jan 24, 2015 2:15 pm

By global I mean a script that will run regardless of where the player is, i.e. what cell is loaded. Specifically, I need to write a script that monitors the player's input and changes character attributes in response. The most straightforward way to accomplish this seems to be write a script with an OnInit() handler that calls RegisterForSingleUpdate(), and so forth. I'm not sure what type of object to attach such a script to, though.

According to the documentation for OnInit() I could do this by attaching the script to a quest that's set to run at startup, although this seems a bit hacky to me. Is there a standard way of doing this? In Unity terms, it seems like it would be better to use something akin to an empty game object.

It's probably worth mentioning that I don't care if the script runs while the player is in menus.

User avatar
Dan Wright
 
Posts: 3308
Joined: Mon Jul 16, 2007 8:40 am

Post » Sat Jan 24, 2015 7:10 am


Not hacky, but common practice! Quest objects don't always have to be used for making missions. If it works, don't argue :P

- Hypno
User avatar
Cameron Wood
 
Posts: 3384
Joined: Wed Oct 31, 2007 3:01 pm

Post » Sat Jan 24, 2015 2:34 am

Haha alright, fair enough. I'll give it a shot.

User avatar
Amber Hubbard
 
Posts: 3537
Joined: Tue Dec 05, 2006 6:59 pm

Post » Sat Jan 24, 2015 7:48 am

Normally, if you want to track something about the player specifically, you use a ReferenceAlias script that belongs to a quest alias that's pointing at the player reference. However, this still requires you to create a dummy start-enabled quest in order to define the alias, so if you're already using a Quest script and got it working, just stick with that. :P

User avatar
Alada Vaginah
 
Posts: 3368
Joined: Sun Jun 25, 2006 8:31 pm

Post » Fri Jan 23, 2015 11:37 pm

I'm not familiar with how aliases work yet so yeah, it sounds like just using a dummy quest is the simpler approach, especially if I need it anyway to serve as a starting point for everything.

User avatar
mike
 
Posts: 3432
Joined: Fri Jul 27, 2007 6:51 pm


Return to V - Skyrim