Script slowing down

Post » Tue Jun 07, 2016 11:05 am

Finally got my water arrow script to work properly and I'm starting to think it's slow and inefficient and want to improve it.


What it does is place an activator where an arrow hits, the activator then checks for light sources and light emitting objects(torch, campfire etc) and disables both, then places the off object. Clean up happens after a set amount of time has passed and the player re-enters the cell or the activator doesn't engage with anything. There are a few main parts, I have removed duplicate entries but left the properties to give you an idea of how many there are so far.



Spoiler


Scriptname AceWaterArrowScript extends ObjectReference

Float TimePassed

Actor Property PlayerRef Auto


;replacement object for doused light objects
Static Property TorchOff Auto
Static Property FireOutSmall Auto
Static Property FireOut Auto
Static Property Campfire01Off Auto
Static Property Campfire01LandOffDirt01 Auto
Static Property Campfire01LandOffRiverbedEdge01 Auto
Static Property Campfire01LandOffCoastBeach Auto
Static Property Campfire01LandOffReachDirt Auto
Static Property Campfire01LandOffRocks01 Auto

;lists that have moveable static light objects
Formlist Property LightSourceList Auto
Formlist Property PermTorchList Auto
Formlist Property FireEmberList Auto
Formlist Property FireEmberSpecialList Auto
Formlist Property AceCampfire01BurningList Auto
Formlist Property AceCampfire01LandBurningList Auto
Formlist Property AceCampfire01LandBurningRiverBedEdge01List Auto
Formlist Property AceCampfire01LandBurningCoastalBeach01List Auto
Formlist Property AceCampfire01LandBurningReachDirt01List Auto
Formlist Property AceCampfire01LandBurningRocks01List Auto

;References for pointing to the new object that is inplace of the old light object
ObjectReference PlacedTorch1
ObjectReference PlacedEmber1
ObjectReference PlacedEmber2
ObjectReference PlacedCampFire01
ObjectReference PlacedCampFireLand
ObjectReference PlacedCampFireRiver
ObjectReference PlacedCampFireCoast
ObjectReference PlacedCampFireReach
ObjectReference PlacedCampFireRocks



Event OnInIt()

TimePassed = Utility.GetCurrentGameTime()

;Checks for nearest X and sets them to the object reference
ObjectReference LightSource = Game.FindClosestReferenceOfAnyTypeInListFromRef(LightSourceList, Self, 180)


;The swapping of objects and disabling the lightsource
If TorchObject1 == True
PlacedTorch1 = TorchObject1.PlaceAtMe(TorchOff)
Float TorchScale = TorchObject1.GetScale()
PlacedTorch1.SetScale(TorchScale)
Utility.Wait(0.6)
LightSource.Disable()
TorchObject1.Disable()
EndIf


EndEvent


;Clean up checking
Event OnCellLoad()

Float NewTime = Utility.GetCurrentGameTime()

If NewTime > (TimePassed+0.1)

CleanUp()

EndIf

EndEvent


State Active

Function CleanUp()
;
EndFunction

EndState


Function CleanUp()

;Same as above, checks for the references.
ObjectReference LightSource = Game.FindClosestReferenceOfAnyTypeInListFromRef(LightSourceList, Self, 200)
LightSource.Enable()


;Enables old, disables new and then deletes everything leaving nothing behind.
If TorchObject1 == True
PlacedTorch1.Disable()
TorchObject1.Enable()
PlacedTorch1.Delete()
EndIf


;Final clean up, removes the activator itself last.
Self.Disable()
Self.Delete()
;Debug.Notification("Enabled")
EndFunction





I can't add a script to movable statics to register an OnHit event so this was the only other option I could think of. I still need to add candles and lamps(any others?) which will further slow this down.


Any ideas?

User avatar
Monika
 
Posts: 3469
Joined: Wed Jan 10, 2007 7:50 pm

Post » Tue Jun 07, 2016 11:54 pm

Have you done any stack profiling yet to see what is causing the issue? http://www.creationkit.com/index.php?title=StartStackProfiling_-_Debug



I had an excel sheet which can help out with it a bit (I'd have to reupload it somewhere as I have no idea where it would be online now...), but basically that will help you track where the potential problem areas are. You can also just post the stack profile here if you want.

User avatar
Rachel Cafferty
 
Posts: 3442
Joined: Thu Jun 22, 2006 1:48 am

Post » Tue Jun 07, 2016 7:01 pm

I just assumed it was because there were so many checks and maybe the SetScale() functions.


www.creationkit.com/index.php?title=SetScale_-_ObjectReference


>Calling this function repeatedly over a short span of time may cause a crash to desktop.


I'm only calling it once per object so I don't think it's that.


I should probably mention what gave me the impression. An object upon enabling was half there, like the opacity was raised or something. Reloading the cell fixed the issue.



It's a pretty simple script so I thought someone might have a better way of doing it.

User avatar
Michael Russ
 
Posts: 3380
Joined: Thu Jul 05, 2007 3:33 am


Return to V - Skyrim