Script initialization question.

Post » Mon Aug 26, 2013 7:11 am

Hi,

I know you're supposed to set up arrays that are global to a script in the OnInit event like so:

int[] blaevent OnInit    bla = new int[123]endevent
Is there any problem when you instead set up the array during the OnPlayerLoadGame event? Or any other event that doesn't happen only once like the OnInit event?

Any help and suggestions are appreciated :smile:
User avatar
cutiecute
 
Posts: 3432
Joined: Wed Sep 27, 2006 9:51 am

Post » Mon Aug 26, 2013 10:27 am

Don't use OnPlayerLoadGame() for intitializing arrays. If you do you re-initialize the array every time a save is loaded, which resets it.

I prefer to initialize arrays in Functions over directly in Events. This gives me more control over whether or not the initialization triggers.

User avatar
Bird
 
Posts: 3492
Joined: Fri Nov 30, 2007 12:45 am

Post » Mon Aug 26, 2013 7:15 pm


Thanks :smile: but I actually left out a detail in my question (d'oh!):

Are there any garbage collection problems which may cause save file bloat over time because you're re-allocating those arrays every time the game loads (assuming you save as well, of course)?

The point you made is a good one, but I already found that out, and simply check an array's length to see if it's set up already (the problem is that I can't use OnInit for myself anymore, because I'm using the mod I'm making as I add features).
User avatar
Annika Marziniak
 
Posts: 3416
Joined: Wed Apr 18, 2007 6:22 am


Return to V - Skyrim