Here's a link - http://www.cipscis.com/skyrim/tutorials/states.aspx
As always, feedback is appreciated.
Cipscis
ScriptName Statesixample extends ObjectReferenceFunction SharedStuff() ;Do stuffEndFunctionAuto State Inactive Event OnActivate(ObjectReference akActionRef) GoToState("Active") EndEvent Function InactiveOnlyStuff () ;Do stuff EndFunctionEndStateState Active Event OnActivate(ObjectReference akActionRef) GoToState("Inactive") EndEvent Function ActiveOnlyStuff () ;Do stuff EndFunctionEndStateA difference of coding style
Event OnActivate(ObjectReference akActivator) bLightsOn = !bLightsOn If bLightsOn If rLight rLight.Enable() Else rLight = PlaceAtMe(LightBase) EndIf Else rLight.Disable() EndIfEndEvent
Auto State LightsOff Event OnActivate(ObjectReference akActivator) If rLight rLight.Enable() Else rLight = PlaceAtMe(LightBase) EndIf GoToState("LightsOn") EndEventEndStateState LightsOn Event OnActivate(ObjectReference akActivator) rLight.Disable() GoToState("LightsOff") EndEventEndState
Function TestSpeed(Int aiIterations = 0, Float afBeginTime = 0.0, Float afEndTime = 0.0) afBeginTime = Utility.GetCurrentRealTime() Debug.Trace("Start: " + afBeginTime) While (aiIterations < 1000) aiIterations += 1 Activate(Game.GetPlayer()) EndWhile afEndTime = Utility.GetCurrentRealTime() Debug.Trace("Finish: " + afEndTime) Debug.Trace("Time Elapsed: " + (afEndTime - afBeginTime))EndFunction
[06/04/2012 - 05:04:38AM] Start: 37.200001[06/04/2012 - 05:05:04AM] Finish: 63.493000[06/04/2012 - 05:05:04AM] Time Elapsed: 26.292999
[06/04/2012 - 05:06:44AM] Start: 40.375999[06/04/2012 - 05:07:10AM] Finish: 66.750000[06/04/2012 - 05:07:10AM] Time Elapsed: 26.374001
Event OnActivate(ObjectReference akActivator) bLightsOn = !bLightsOn If bLightsOn rLight.Enable() Else rLight.Disable() EndIfEndEvent
Auto State LightsOff Event OnActivate(ObjectReference akActivator) rLight.Enable() GoToState("LightsOn") EndEventEndStateState LightsOn Event OnActivate(ObjectReference akActivator) rLight.Disable() GoToState("LightsOff") EndEventEndState
Event OnActivate(ObjectReference akActivator) If rLight.IsDisabled() rLight.Enable() Else rLight.Disable() EndIfEndEvent