Hey Guys, I need some help with a simple(ish) script that I'm writing to control lights. Specifically, to check whether the lights have been built AND then cycle them through on-off states depending on the time of day.
For those of you who have built house mods or location mods, this might be familiar: I'm trying to adapt cipscis/m3rvin's automatic light switch resource, but my script won't compile.
Cipscis/m3rvin's automatic light switch resource
http://www.creationkit.com/Light_Switch[1]
http://www.nexusmods.com/skyrim/mods/14894/?[2]
Basically the script takes two float values corresponding to the time to turn the lights on (say 6PM) and to turn the lights off (say 6AM). When the appropriate time threshold is passed, the script switches between a "lights Off" and "lights On" state. The script is usually attached to an enableparent for the lights, typically an XMarker, and just cycles between states happily.
The problem with this system is that one set of objects is ALWAYS on.
The goal is therefore to write a script that can check that an object reference, which is only enabled when the lights are "crafted" is enabled. And THEN, and ONLY then, to cycle between on off states.
My Script
Normally, you have the objects that show when the lights are ON and those that show when the lights are OFF attached to the SAME XMarker, just with opposite enable states.
My script runs on a controller object which is always enabled. This is intended to be an XMarker.
Two more markers, respectively MarkerLightsOn and MarkerLightsOff act as enableparents for the "lights on" objects and "lights off" objects.
Finally, a last marker - the BuildMarker is enabled or disabled when the object is crafted at a house workbench, like the hearthfire stuff - an item is "crafted", at which point another script attached to that will enable the BuildMarker and promptly remove itself from the players inventory.
I've written the script, but it's failing to compile. I think there's something wrong with the way I've written the LightsBuiltCheck function, but I don't yet know papyrus well enough to troubleshoot appropriately. Could anyone help? The script I've come up with below:
Scriptname BuildableAutomaticLightSwitch extends ObjectReference{Cipscis and M3rvin's Automatic Light Switch adapted for buildable lights.} float Property LightsOffTime = 6.0 auto{The time at which lights should be turned off}float Property LightsOnTime = 18.0 auto{The time at which lights should be turned on}ObjectReference Property MarkerLightsOn auto{The marker controlling the "lights on" object references}ObjectReference Property MarkerLightsOff auto{The marker controlling the "lights off" object references} float Function GetCurrentHourOfDay() global{Returns the current time of day in hours since midnight} float Time = Utility.GetCurrentGameTime() Time -= Math.Floor(Time) ; Remove "previous in-game days passed" bit Time *= 24 ; Convert from fraction of a day to number of hours Return Time EndFunction Function RegisterForSingleUpdateGameTimeAt(float GameTime){Registers for a single UpdateGameTime event at the next occurrenceof the specified GameTime (in hours since midnight)} float CurrentTime = GetCurrentHourOfDay() If (GameTime < CurrentTime) GameTime += 24 EndIf RegisterForSingleUpdateGameTime(GameTime - CurrentTime) EndFunction Function LightsBuiltCheck( ObjectReference BuildMarker) {Checks to see if BuildMarker object ref is enabled, and if it is, cycles between the "LightsOn"/"LightsOff" states. If it is disabled, it will go to the LightsNotBuilt State.} If (BuildMarker.IsDisabled()) If (GetCurrentHourOfDay() > LightsOffTime) GoToState("LightsOff") Else GoToState("LightsOn") EndIf Else GoToState("LightsNotBuilt") EndIf EndFunction Event OnInit()LightsBuiltCheckEndEventState LightsOff Event OnBeginState() Disable(MarkerLightsOn) Enable(MarkerLightsOff) RegisterForSingleUpdateGameTimeAt(LightsOnTime) EndEvent Event OnUpdateGameTime() GoToState("LightsOn") EndEvent EndState State LightsOn Event OnBeginState() Disable(MarkerLightsOff) Enable(MarkerLightsOn) RegisterForSingleUpdateGameTimeAt(LightsOffTime) EndEvent Event OnUpdateGameTime() GoToState("LightsOff") EndEvent EndStateState LightsNotBuilt Event OnBeginState() Disable(MarkerLightsOff) Disable(MarkerLightsOn) RegisterForSingleUpdateGameTimeAt(LightsOnTime) RegisterForSingleUpdateGameTimeAt(LightsOffTime) EndEvent Event OnUpdateGameTime() GoToState("LightsBuiltCheck") EndEvent EndState