Jump to content

Light switch


iTz Rossss X

Recommended Posts

Hello,

 

I've been making my own script that turns a light on and off. Here it is...

 

scn aaaPrivateVaultLightSwitch01SCRIPT

 

Begin OnActivate

 

if aaaPrivateVaultYellowLight01REF01.getdisabled == 1;

aaaPrivateVaultYellowLight01REF01.enable

else

endif

aaaPrivateVaultYellowLight01REF01.disable

end

 

As you can see i've been using references. Because the light switch is an activator, is there anyway I can change the script so that it disables and enables it's enable parent? If I have to use references I will have to make like 10 different switches and scripts :S

 

Thanks for reading,

 

~~iTz

Link to comment
Share on other sites

Best way is to make one light the enable parent of all the other lights. Pick a light and make it persistent and give it an editor reference ID. Then go to all the other lights enable parent tab and set the enable parent to your persistent light. Now just use this code on your switch (with the persistent light named MyLightref).

 

 

 

scn aaaPrivateVaultLightSwitch01SCRIPT

Begin OnActivate

 If MyLightRef.GetDisabled
MyLightRef.Enable
 Else
MyLightRef.Disable
 Endif
 Activate
End

 

Note: If you want all the lights off initially, just set the persitent light as initially disabled as well.

Link to comment
Share on other sites

Actually, no. You don't need to decalre MyLightRef because its not a reference variable. Its already declared as the reference editor ID of the light. Once you give an object an editor reference ID and make it persistent, you can use it explicitly in any script. Its the same as using "player." or "SomeNPCRef." in a script. You don't declare those do you?
Link to comment
Share on other sites

With simple scripts like this, it's often a good idea to make them work in a general case so that you can reuse it elsewhere without having to edit it. In this case, the script could be made reusable by using a Linked Ref, and getting the light reference via GetLinkedRef rather than hard-coding it:

ref rLinkedRef

Begin OnActivate

if rLinkedRef == 0
	set rLinkedRef to GetLinkedRef
endif

if rLinkedRef.GetDisabled
	rLinkedRef.Enable 0
else
	rLinkedRef.Disable 0
endif

Activate; You only need this line if the switch has a default activation action

End

Cipscis

 

EDIT:

 

If you want your references to be easy to find, consider using a meaningful string within the editorID rather than just prefixing all of your editorIDs with "aaa". That way you can find them by using the GECK's filter or by sorting by formID.

 

Cipscis

Link to comment
Share on other sites

Actually, no. You don't need to decalre MyLightRef because its not a reference variable. Its already declared as the reference editor ID of the light. Once you give an object an editor reference ID and make it persistent, you can use it explicitly in any script. Its the same as using "player." or "SomeNPCRef." in a script. You don't declare those do you?

Oh, right.

 

I just glanced at it. I didn't realize that you weren't using GetLinkedRef, which you should be.

 

 

The script that Cipsis posted would require you to declare a variable.

Link to comment
Share on other sites

how do i apply the code to the switch? I can't get mine to turn the lights on/off at all. just having all around problems with this. :wallbash: I'm doing the whole parent light thing and connecting them as described above. just not working at all. do i link the switch to mylightref or what?
Link to comment
Share on other sites

In the switch's object properties (double-click it in the list), select your script from the drop down.

 

In the switch's reference properties (double-click it in the cell), find the link (or something like that) tab, click 'find reference in render window' and click on the parent light.

Link to comment
Share on other sites

In the switch's object properties (double-click it in the list), select your script from the drop down.

 

In the switch's reference properties (double-click it in the cell), find the link (or something like that) tab, click 'find reference in render window' and click on the parent light.

 

:wallbash: :wallbash: :wallbash: :blink: dizzy.

 

Not working.

 

maybe this will help.

 

Still nothing. And I'm not doing anything different other then the naming of my xmarker.

 

I use to code in Qbasic and on ti-86 calculators. I understand the whole endif enable and all those other operations. I don't see, however, how to enable and disable the xmarker. That's not my switch. The electrical switch is my switch. It's what, in the game, i hit to turn the lights on. I feel like I'm running you in circles.

 

all the lights are linked to the xmarker. called x4. it's presistent and initially disabled. the electrical switch i want to control the lights with in game is called x4switch. in the script called x4switchscipt i have this code;

 

scn x4switchscript

 

Begin OnActivate

 

If X4.GetDisabled

X4.Enable

Else

X4.Disable

Endif

Activate

End

 

it all saves fine.

 

I run fomm enable the esm as 01 after fallout3.esm. go to the location. hit the switch and nothing still.

 

So, this is the circle part. What is the part I'm missing inorder to make it so that i hit the switch and the lights go on. agian and they go off>?

Link to comment
Share on other sites

I have a funny felling i need the activator line in there that cipscis put in.

 

ref rLinkedRef

 

Begin OnActivate

 

if rLinkedRef == 0

set rLinkedRef to GetLinkedRef

endif

 

if rLinkedRef.GetDisabled

rLinkedRef.Enable 0

else

rLinkedRef.Disable 0

endif

 

Activate; You only need this line if the switch has a default activation action <------ :blink:

 

End

 

 

Could this be where I would put the electrical switch name? the switch name is x4switch jic.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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