Jump to content

If "Scripting" Than "Beat Head Against Hard Surface"


OldWorthington

Recommended Posts

Hello all,

 

Played Oblivion ages ago, and I've just recently come back to it.

 

I thought "wouldn't it be cool if the 'street light' and 'light switch' scripts could be combined?".

 

So I dusted off my (admittedly rusty, also, limited) coding skills and had a few kicks at the can.

 

That was 6 hours ago ..

 

However, unlike normal, where I just determine that something isn't possible (at least for me) this time it *looks* like it should work, but doesn't.

 

So I come here for guidance.

ScriptName aaLightSwitchStreetlightScript

ref parent

Begin OnActivate
	set parent to getParentRef
	if GetDisabled == 0
		if parent != 0
			if parent.getDisabled == 0
				parent.disable
			else
				parent.enable
			endif
		endif
		disable
	else
		if parent != 0
			if parent.getDisabled == 0
				parent.disable
			else
				parent.enable
			endif
		endif
		enable
	endif
End

Begin GameMode

	If (xQuartersON.getDisabled == 0)
		If ((gamehour >= 20) || (gamehour < 8)) && getDisabled == 1
			Enable
		EndIf
	Elseif getDisabled == 0
;		Disable
	EndIf

End

Thanks in advance for any help!

 

 

 

PS

 

Another, more general problem I've often encountered is the inability to 'daisy-chain' items together when scripting. I *know* it's possible, but I can figure out how to do it.

 

I've tried a couple of times to replicate the Portal to Cameron's Paradise in another mod of mine, because it looks cool. For whatever reason I can't get it to work.

 

But I'm less focused on that 'project' right now, and besides, I don't want to go dumping too much on you all at once, lol

 

 

Link to comment
Share on other sites

Well, I don't know the two original scripts you're aiming to combine, and right now also can't go and look them up, but the OnActivate block is self-explanatory, a daisy-chained toggle disabling/enabling first the parent, then itself.

 

What's the GameMode block meant to do though? If something called xQuartersOn is not disabled and the time of day is between 20 and 8 and the switch is disabled, then the switch will be enabled?

 

What's enabling the switch doing here? Will it also trigger activation? Because if not, then this will not do anything to the parent (I guess the light source in question?) either. And it's good you commented out the Disable line for when the switch is not disabled, because as this is a GameMode block on an object, it will be run every frame, and this line will unconditionally make it so the switch is disabled at every time.

 

I don't know how exactly switches work and what disabling them does. But every other object that I disabled so far has always only disappeared from the game world, until I re-enabled it again later. This is likely the right way to turn off light sources, from all I know, but switches also? I think it will just make them disappear.

 

A switch needs activation, not enabling/disabling, unless I'm missing a really critical part of how switches toggle their animation states. But from all I know so far this is rather done by PlayGroup forward or backward instead. Though if the original Vanilla scripts worked that way, it's safe to assume it's done that way, and I just don't know anything about switches.

 

Still, enabling/disabling the switch in the GameMode block will not make the OnActivate block and the daisy-chain toggle run.

Link to comment
Share on other sites

Ok, I understand your confusion.

 

xQuartersOn is the ON part to a Light switch pairing.


ref parent

Begin OnActivate
	set parent to getParentRef
	if GetDisabled == 0
		if parent != 0
			if parent.getDisabled == 0
				parent.disable
			else
				parent.enable
			endif
		endif
		disable
	else
		if parent != 0
			if parent.getDisabled == 0
				parent.disable
			else
				parent.enable
			endif
		endif
		enable
	endif
End

That's the light switch script - I thought it was part of the original game. Guess it wasn't?

 

Basically, it's meant to toggle 2 identical items back and forth. One being an enabling Ref for a bunch of other stuff.


begin gamemode

if gamehour >= 18 || gamehour < 7
	enable
	else
		disable
endif

end

That's the streetlights script. It enables something between X and Y hours.

 

What I want to do is make it so that if my Enabling item (xQuartersOn) is disabled, it will enable at hour 20 / disable at hour 08. However, I also want to be able to 'force' it to enable on activation.

 

I've tried running the streetlights script on another item and having that enable the 'xQuartersOn', but that doesn't seem to actually work. Which I find odd, but. like I said, I'm rusty.

 

Hell, I'm not even sure if it's possible.

Link to comment
Share on other sites

Ah, yes, that's slowly making more sense.

 

The streetlight script is doing exactly what it should be doing, running on the lights themselves, or an "enable parent" for them, it makes it so the lights will be enabled between 18 and 7, and disabled every other time.

 

The light switch script may very well be from the Vanilla game. I may be a scripter, but I don't have every single script in memory now. :sweat:

 

But I think we need to have a better overview of what objects there are, what they're called and meant to do, and which script is running on which object.

 

 

The "enable parent" daisy-chaining works pretty much without scripts. Every object that has an "enable parent" set will enable/disable when this parent is enabled/disabled. You can, for example, daisy-chain a whole group of lights by making one of them the "enable parent" for all the others, and then you'll only need to enable/disable that one light and all others will automatically follow suit.

 

I'm not quite sure what the purpose is of this backwards daisy-chain on the light switch script. Is the script really running on the switch? Due to the enable/disable calls I somehow doubt that. What is the parent of the object the switch script is running on? Why is it necessary to pass the enable/disable state through to the parent, i.e. backwards?

 

Or is it two enabling/disabling objects connected, one the parent and one the child, thus when the parent gets toggled it also toggles the child, via "enable parent", and when the child is toggled it also toggles the parent, via the scripted backwards daisy-chain?

 

That's why I think we'll also need the "setup" here, to understand what what is meant to do and how.

 

 

I'll take a closer look into the Vanilla scripts today, if I get the time, so I'll know at least how the Vanilla game situations have set this up to understand. This enabling and disabling of switches confuses me, as I'm almost convinced it won't do a thing, but I don't even know if what's disabled here even is a switch, or something else entirely.

 

 

For what it's worth, you should be able to simply set this up via only one auto-switching and switchable light, which is set up as "enable parent" for all others, and will only need another script on a switch to toggle this, like so:

 

Script on the switch, the actual physical object you push/activate in order to toggle the light:

Begin OnActivate
    if MyAutoLight.GetDisabled
        MyAutoLight.Enable
    else
        MyAutoLight.Disable
    endif
    Activate ;just in case the activation is needed e.g. for toggling a render state or animation
End

Script on the light, EditorID/Persistent reference "MyAutoLight":

short sDidNight
short sDidDay
 
Begin GameMode
    if GameHour >= 18 || GameHour < 7
        set sDidDay to 0 ;reset day flag during night
        if sDidNight == 0
            Enable
            set sDidNight to 1 ;do only once, do not repeat every time you turn the light off manually during night
        endif
    else
        set sDidNight to 0 ;reset night flag during day
        if sDidDay == 0
            Disable
            set sDidDay to 1 ;do only once, do not repeat every time you turn the light on manually during day
        endif
    endif
End

This should work, in theory. Maybe it'll have some oddities when you quick-wait from one day/night into another without passing the day though, but that remains to be tested.

 

But I'll have to take a deeper look at how switches are done in the Vanilla game. :ermm:

Link to comment
Share on other sites

Drake is right,

need one switch to toggle it Enable/Disable. and that one switch is the PARENT

 

just recently I found out that every child object (have parent) can't be disabled in-game

for test case, go to Copious Coin Purse in IC Market district (Thoronir's shop)

in there you can find several world object items that have parent

try opening console, click the object, and disable it... I'm pretty sure you can't disable it. that is child characteristic

you can ONLY disable it by disabling the parent

Link to comment
Share on other sites

  • 2 weeks later...

Drake is right,

need one switch to toggle it Enable/Disable. and that one switch is the PARENT

 

just recently I found out that every child object (have parent) can't be disabled in-game

for test case, go to Copious Coin Purse in IC Market district (Thoronir's shop)

in there you can find several world object items that have parent

try opening console, click the object, and disable it... I'm pretty sure you can't disable it. that is child characteristic

you can ONLY disable it by disabling the parent

 

I put the project on hold, but what what I've recently learned about what you just said (was doing something totally different, but came upon a solution - i think).

 

Anyways, I shall give it another go now. Thanks all.

Link to comment
Share on other sites

I have suggestion

if you can't disable the child

you can always move it to something like SetPos Z -5000 (from its original location)

so the child is disappear from player's view

not entirely disabled,

but at least the object is gone from the view.

and you can restore its original position later, by using syntax GetStartingPos Z and SetPos Z

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...