Jump to content

Combining scripts question


Recommended Posts

I have in my patches mod, scripts that just use SKSE and versions of these scripts that are for SkyUI and MCM, I would like to replace those with scripts that detect if SkyUI is installed (this I know how to do) and then run acccordingly, could this be as simple as putting all code from two scripts in one new script and making each copy a separate state with the detection in the empty state? I believe that states can have the same events in them?

Or are there traps waiting to catch me? Will a script that is twice the size(ish) be a performance problem? I assume that functions common to states can be left in the empty state and thus only defined once?

 

 

diziet

Link to comment
Share on other sites

As IsharaMeradin said, make a back up before attempting to do that !!.


My suggestion would be to make a 'Test' esp with some 'Test' scripts to learn how 'States' works, i'm saying this because your question:

"could this be as simple as putting all code from two scripts in one new script and making each copy a separate state with the detection in the empty state? I believe that states can have the same events in them?"

Clearly shows that you are not familiar with how 'States' works and all of their potentials.


First of all, for doing such a thing, there are no 'Empty States', but you can call them 'Sequences', an 'Empty State' is EMPTY and does not do anything.


Second, each state can have the same or even more 'Events' in them from the previous 'States', and so on...


Third, experiment first with 'States', it's not difficult to learn their functionality, the hard thing is to develop the 'Thinking Logic' so that you can use the 'State's' potentials.


Have a pleasant day.

Edited by maxarturo
Link to comment
Share on other sites

 

First of all, for doing such a thing, there are no 'Empty States', but you can call them 'Sequences', an 'Empty State' is EMPTY and does not do anything.

To be technical, all code outside of named states is within the "empty state". At least that is how Bethesda defined it when explaining how to use states: https://www.creationkit.com/index.php?title=States_(Papyrus)

Link to comment
Share on other sites

Yes IsharaMeradin, you are correct.

What i was trying to say is that, a state that will be used to handle / define / assign the functionality and the use of what version of the script should run, can not be 'Empty' or even be called as 'Empty'.


At least this is what i understood that dizietemblesssma wants to achieve.

Example:


Bool Property VersionA = False Auto

Bool Property VersionB = False Auto

And so on...


; This is the State that defines the used of what version of the script should run

AUTO STATE Sequence01

EVENT OnLoad()

If ( VersionA == True )

GoToState("Sequence02")

ElseIf ( VersionB == True )

GoToState("Sequence03")

ElseIf

And so on.....

EndIf

ENDEVENT

ENDSTATE



STATE Sequence02 ; Script Version A

EVENT SomeEvent01....

ENDEVENT


EVENT SomeEvent02....

ENDEVENT


EVENT SomeEvent03....

ENDEVENT

ENDSTATE



STATE Sequence03 ; Script Version B

EVENT SomeEvent01....

ENDEVENT


EVENT SomeEvent02....

ENDEVENT


EVENT SomeEvent03....

ENDEVENT

ENDSTATE



Have a nice day.

Edited by maxarturo
Link to comment
Share on other sites

 

Yes IsharaMeradin, you are correct.
What i was trying to say is that, a state that will be used to handle / define / assign the functionality and the use of what version of the script should run, can not be 'Empty' or even be called 'Empty'.
At least this is what i understood that dizietemblesssma wants to achieve.

That is basically what I wanted to achieve, but I was under the impression that I needn't 'name' the sequence01 state with the prefix AUTO, but that just putting the

EVENT OnLoad()

        If ( VersionA == True )

              GoToState("Sequence02")

  ElseIf  ( VersionB == True )

              GoToState("Sequence03")

  ElseIf  

              And so on.....

  EndIf

ENDEVENT

would suffice, and that would be treated as the 'default' state?

 

There are some functions that are identical in the existing scripts, is there any advantage to either leaving them as they are and defining 'dummy' functions outside the states or renaming them to be different and defining them outside the states?

 

 

diziet

Link to comment
Share on other sites

You can have your custom functions that are identical located in the script's "empty state". Since there won't be a function by that name in the current state and there won't be a function by that name on the script being extended it will use the version found in the local script's "empty state". And for functions that need to be different for each state, a "do nothing" version can be in the empty state while coded differently inside each state as required.

 

For example:

 

;in scripts empty state
EVENT OnLoad()
  If ( VersionA == True )
    GoToState("Sequence02")
  ElseIf  ( VersionB == True )
    GoToState("Sequence03")
  ElseIf  
    ;And so on.....
  EndIf
ENDEVENT

Function SharedFunctionA()
  ;do shared stuff
EndFunction

Function StateUniqueFunctionA()
  ;empty - defined within the necessary states but must be present for compiler to not complain
EndFunction

State Sequence02
  Event OnActivate(ObjectReference akActivator)
    SharedFunctionA()
    StateUniqueFunctionA()
  EndEvent

  Function StateUniqueFunctionA()
    ;do unique stuff
  EndFunction
EndState

State Sequence03
  Event OnActivate(ObjectReference akActivator)
    SharedFunctionA()
    StateUniqueFunctionA()
  EndEvent

  Function StateUniqueFunctionA()
    ;do other unique stuff
  EndFunction
EndState

 

 

 

Link to comment
Share on other sites

IsharaMeradin already answered your question.


I'm just adding that, the 'State' with a prefix "AUTO STATE" will be treated as the first / the default state on the script's 'State Sequence'.


Beware that: If all of your events are inside a state, and none of them have assigned an "AUTO STATE", your script will do NOTHING !, in this case the group of events you need to fire first need to have assigned the "AUTO STATE".


Have a nice week.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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