Jump to content

Super Light Switch help please!


iwillwin

Recommended Posts

Ok, so I'm trying to link a activator to a message and the message tells my script to turn on/off lights, here's my script:

 

;---------------------------------------------------------

Scn AASwitch01Script

short Done
short Button
short Go
ref light
begin OnActivate

if IsActionRef player == 1
	ShowMessage AAswitch01message
	set Go to 1
endif

end

begin gamemode



set Button to GetButtonPressed

if ( Button == 0 ) && ( Go == 1 )
	if light == 0
	set light to AAlightAREF
endif

if light.GetDisabled
	light.Enable
else
	light.Disable
endif
	Set Go to 0
Activate
endif
elseif ( Button == 1 ) && ( Go == 1 )
	if light == 0
	set light to AAlightBREF
endif

if light.GetDisabled
	light.Enable
else
	light.Disable
endif
	Set Go to 0
Activate
endif
elseif ( Button == 2 ) && ( Go == 1 )
	Set Go to 0
endif
end

;------------------------------------------------------------

 

Message button 0 is: Turn on/off lights in section A

Message button 1 is: Turn on/off lights in section B

Message button 2 is: Exit

 

I'm no pro at messing around with scripts but i just cant seem to get it to work, no matter which button i choose ( 0 or 1 ) They still turn off my light A and never my light B. Can someone please look over my script and see what I'm doing wrong?

Link to comment
Share on other sites

I think you have one too many endifs before you get to the chunk that controls the B lights. The endif after the first activate would prevent the elseif right after from running, if I'm figuring correctly.

 

Also, it seems a little overly complicated. I would just used AAlightAREF.enable and AAlightBREF.disable, with a GetDisable if block to see if they're on or not.

 

-Pax

Link to comment
Share on other sites

Pax1138 is correct, you have too many "endif" statements - you have 8 "endif" statements but only 6 "if" statements. This will lead to pretty unpredictable behaviour in your script, as the conditional logic is incorrect.

 

One way that helps to make sure that you don't include an incorrect number of "endif" statements is to indent your scripts correctly. If you don't know how to do this, here is a page that can do it for you - Script Indenter

 

Personally, I prefer to use AddItem to add a scripted token (an unplayable, therefore invisible, piece of armour) to the player's inventory that contains the menu script in a GameMode block instead of using a "switch" variable ("Go" in this case), as the GameMode block won't be running in the background when it is unneeded.

 

If I were just to change your script, and not convert it to my preferred method of using tokens (not that I would use it that way), it would look like this:

ScriptName AASwitch01Script

short button
short go

Begin OnActivate player
ShowMessage AAswitch01message
set go to 1
End

Begin GameMode
if go
	set button to GetButtonPressed
	if button == -1
		Return
	elseif button == 0
		if AAlightAREF.GetDisabled
			AAlightAREF.Enable 0
		else
			AAlightAREF.Disable
		endif
	elseif button == 1
		if AAlightBREF.GetDisabled
			AAlightBREF.Enable 0
		else
			AAlightBREF.Disable
		endif
	endif
	Set Go to 0
	Activate
endif
End

Cipscis

Link to comment
Share on other sites

Thank you both, and the script works perfectly in game. Like i said, I'm an extreme novice at scripting and i learned everything i know ( however little it is) by dissecting other peoples scripts.

Everything in the new script that Cipscis provided makes sense to me except:

 

if button == -1

Return

 

Also, does anyone have any links or tutorials so i can learn scripting?

And Cipscis your way of using additem is interesting and i would like to know how it works, and being the novice i am I'm bound to ask newbish questions... like, does the GameMode block running in the background affect anything? FPS, PC performance?

Link to comment
Share on other sites

The "Return" command basically tells the script to stop processing for that frame, so that no code below it will be executed. I've used it in this case so that some code will only run if "button == -1" returns false (the "reset" portion of code - "set go to 0")

 

Having a GameMode block running in the background checking a condition every frame will theoretically have an effect on performance, but it's likely to be pretty insignificant - like decreasing your framerate by 0.01 fps or something. However, if this method is used often (especially for more intensive things than just checking a condition) then it might start to have a noticeable effect. I personally prefer to use a scripted token because of this, but to be honest it doesn't really make that big a difference in a case like this.

 

A good scripting tutorial is available on the Oblivion CS Wiki, it's called "My Second Script". Although it was written for Oblivion, Fallout 3 uses essentially the same syntax - only some functions are different (perhaps most noticeable is the replacement of MessageBox with ShowMessage).

 

I'm planning on writing a scripting tutorial of my own soon for my upcoming website, but I'm fairly busy at the moment so I don't know how long it'll take me.

 

Cipscis

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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