Preserving Variables between Events in a Script

Post » Thu Jun 21, 2012 5:40 pm

If I define a variable in one event on an activemagiceffect script (e.g. Event OnEffectStart), how can I ensure that the variable retains its value for another event (e.g. Event OnEffectFinish)? I haven't had any luck with this so far.

Thanks.
User avatar
kirsty williams
 
Posts: 3509
Joined: Sun Oct 08, 2006 5:56 am

Post » Thu Jun 21, 2012 7:48 pm

You can declare variables outside of the events, just like properties, and then they and their values will be "global" for the script and its events. So declare outside, then set a value in OnEffectStart, and read that value in OnEffectFinish. Or is that not useful for what you're trying to accomplish?
User avatar
Sophie Miller
 
Posts: 3300
Joined: Sun Jun 18, 2006 12:35 am

Post » Fri Jun 22, 2012 1:28 am

I've always been declaring them as properties up 'til now, I didn't realize that was a separate thing - going to give that a try and see if it works.
User avatar
Marine Arrègle
 
Posts: 3423
Joined: Sat Mar 24, 2007 5:19 am

Post » Thu Jun 21, 2012 10:38 am

Yep, you can declare variables like...

Int iMyVar
or
Int iMyVar2 = 0

...in the body of the script outside of events/functions, and then those variables will be globally available throughout the script. Unlike using properties for this purpose, such variables cannot be set/get via outside scripts, or used in conditions. But for logic that is purely local to the script, they should work.

(Note: array variables are a little different from the above in that you can't set a default value outside of events. You can do...

String[] aStatsToTrack

...but you cannot do...

String[] aStatsToTrack = new String[10]

...for example, outside of an event or function.)
User avatar
Trent Theriot
 
Posts: 3395
Joined: Sat Oct 13, 2007 3:37 am

Post » Fri Jun 22, 2012 1:38 am

Just to clarify, variables and properties initialised outside fuctions can only be initialised to http://www.creationkit.com/Literals_Reference. Only if declared within a function (remember, events are functions too) can you initialise them using an http://www.creationkit.com/Expression_Reference.

Cipscis
User avatar
Prue
 
Posts: 3425
Joined: Sun Feb 11, 2007 4:27 am


Return to V - Skyrim