How can I make script properties optional

Post » Mon Feb 03, 2014 5:55 pm

I've seen this done in other scripts but aren't sure how to implement it into my own. Take a look at this example script...

Actor Property Actor1 AutoObjectReference Property Dest1 AutoQuest Property MyQuest AutoInt Property PreReqStage AutoInt Property StageToSet AutoEvent OnTriggerEnter(objectreference akactionref)if akactionref == game.getplayer()if MyQuest.GetStage() == PreReqStage    Actor1.Moveto(Dest1)MyQuest.SetStage(StageToSet)    Endif    EndifEndevent

How can I make the PreReqStage optional? Or even both the PreReqStage and StageToSet? Basically it would cut down on scripting very similar scripts where one requires a PreReqStage and another doesn't or one sets a stage whereas in another scenario I don't want a stage to be set just PreReqStage and move the actor.

Thanks.

User avatar
Anthony Diaz
 
Posts: 3474
Joined: Thu Aug 09, 2007 11:24 pm

Post » Mon Feb 03, 2014 7:52 pm

Well, you can design your script with the knowledge that, if the properties aren't filled, they will have their default value (0, 0.0, false, or none, depending on the variable type). So, for instance:

Actor Property Actor1 AutoObjectReference Property Dest1 AutoQuest Property MyQuest AutoInt Property PreReqStage AutoInt Property StageToSet AutoEvent OnTriggerEnter(objectreference akactionref)  if akactionref == game.getplayer()     if  (PreReqStage != 0)  ;this will always be false if PreReqStage isn't filled        if  (MyQuest.GetStage() == PreReqStage)           if  (StageToSet != 0)  ;this will always be false if StageToSet isn't filled              MyQuest.SetStage(StageToSet)           endif           Actor1.Moveto(Dest1)        endif     else        if (StageToSet != 0)           MyQuest.SetStage(StageToSet)        endif        Actor1.Moveto(Dest1)     endif  endifEndevent

This script will do the following:

if StageToSet and PreReqStage are both unfilled/unused:

- Actor will be moved to Dest1

if PreReqStage is filled but StageToSet is not:

- Actor will be moved to Dest1 only if PreReqStage is met

if StageToSet is filled but PreReqStage is not:

- Actor will be moved to Dest1 and Quest will be advanced to StageToSet

if both are filled:

- Actor will only be moved to Dest1 if PreReqStage is met, and StageToSet will only be set if PreReqStage is met.

User avatar
Michael Korkia
 
Posts: 3498
Joined: Mon Jul 23, 2007 7:58 pm


Return to V - Skyrim