Jump to content

How to make one script that responds to activation of multiple push buttons?


Recommended Posts

But quests are pretty much "premade state machines", so why not use them for what they are designed to do, right?

 

Be a bit careful with that approach. They are like state machines, but they only go forward. If you do

quest q = whatever

q.setstage(20)
; do stuff
q.setstage(10)

Then when you come to test the quest stage, you'll find it still at 20. The difference is that stage 10 won't be marked as completed until after the second setstage call, but you can't actually put the quest back to stage 10.

 

I know this because I tried using a quest as a formal finite state automata back in Skyrim. Took me ages to figure out why it wasn't working.

Link to comment
Share on other sites

For more complicated issues you can also use functions nested in conditional quest scripts. For instance you can apply something like this on a quest script

Scriptname MyScript extends Quest Conditional
Int Property Status Auto Conditional

Function IncreaseValue()
Status = Status +1
Self.setstage(1)
EndFunction

Function DecreaseValue()
Status = Status -1
Self.setstage(1)
EndFunction

and then apply something like these functions to several repeatable quest stages. Using (Of course more complicated) conditional quest scripts can be useful for activators and triggers, especially if you want to store something long time.

Link to comment
Share on other sites

I'd create two scripts, one for the buttons and one for the handler quest.

 

A script attached to each Button's object reference.

Scriptname ButtonScript extends ObjectReference Const

Group Buttons
ObjectReference Property Button01 Auto Const
ObjectReference Property Button02 Auto Const
ObjectReference Property Button03 Auto Const
endGroup

Group Globals
GlobalVariable Property ButtonIndex Auto Const
endGroup


Event OnActivate(ObjectReference akActionRef)
	If Self == Button01
		ButtonIndex.SetValueInt(1)
		(ButtonHandler as ButtonHandlerScript).HandleOnButtonPress()
	ElseIf Self == Button02
		ButtonIndex.SetValueInt(2)
		(ButtonHandler as ButtonHandlerScript).HandleOnButtonPress()
	ElseIf Self == Button03
		ButtonIndex.SetValueInt(3)
		(ButtonHandler as ButtonHandlerScript).HandleOnButtonPress()
	EndIf	
EndEvent

And another script attached to a handler quest.

Scriptname ButtonHandlerScript extends Quest Const

Function HandleOnButtonPress()
	If ButtonIndex.GetValueInt() == 1
		Function01()
	ElseIf ButtonIndex.GetValueInt() == 2
		Function02()
	ElseIf ButtonIndex.GetValueInt() == 3
		Function03()
	EndIf
EndFunction
Edited by LarannKiar
Link to comment
Share on other sites

  • Recently Browsing   0 members

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