Thanks for the reply!
I did take your version into account - but there are some things I changed there. I don't keep track of "pause" because with the separated scripts that's not needed anymore. OFF doesn't run in GameMode at all and ON only runs when it's not disabled, that being the only time it should run anyway.
And I don't keep track of time. Your script added the time up inside a variable, and stopped the lamp when the time reached 4. I just thought its easier to simply compare the current time with the hour the oil was added and when that reaches 4 then just stop. Unless I'm missing something, it's simpler that way.
Thanks for the "hasOil" thing - it does make more sense like that. And thanks for the +24 hours for when going into the other day; don't know how I missed that.
With that said, your version of the OFF is the same as mine, with the exception that you're changing the "recorded" hour and day on every activation, while I keep the one with the oil.
On the ON side, parent.enable is required. If you have "Set Enable State Opposite of Parent" checked, then the "son" goes on when the "parent" goes off, but when the son goes off, the parent doesn't go on by itself.
Is there any reason you'd rather have the parent thing in the GameMode block instead of the onActivate one? I'd think it's better to have a minimum amount of code in GameMode as that one gets processed over and over.
The other variant for keeping track of time is borked. I looked it over again and it doesn't work right. The idea was to see when the lamp goes ON and save the hour and day inside the ON script. That would remove the necessity of going over into the other one for these values. The bad part is that there's no way of knowing if the lamp was just fueled or not.I was thinking that if I got the OFF lamp to "figure" that it became enabled not by the "onActivate" block but because the ON one went out (due to lack of oil), that would remove the last inter-script variable hassle.
I thought I'd try your script in the CS, just to see if it would work - in the way it's pasted here, I get the same error as I did with mine - it doesn't compile at "parent.day". I changed it to:
Spoiler scriptName ccLampLightONref parentfloat timefloat hour ;1short day ;2short hasOil ;3begin onactivate disable parent.enableendbegin GameMode if parent if getDisabled return else set day to parent.day ;4 set hour to parent.hour ;5 printc "parent hour: %.2f", hour ;6 printc "parent day: %.2f", day ;7 if (day == GamedaysPassed) set time to time + (GameHour - hour) else set time to time + (GameHour - hour) + 24 endif printc "parent hour old (should be same as above): %.2f", parent.hour ;8 set parent.hour to getCurrenttime printc "parent hour new: %.2f", parent.hour ;9 if (time < 4) return endif printc "parent hasOil: %.2f", hasOil ;10 set parent.hasOil to 0 printc "parent hasOil (should be 0): %.2f", hasOil ;11 set time to 0 disable parent.enable endif else set parent to getParentRef ; or use onload block endifend
but this crashes my CS when I try to save it. No idea why, it's really weird. I added comments to the new lines. And I've changed parent.* into *, where appropriate.