DoOnce (script)

Post » Mon Jun 18, 2012 4:10 pm

Is their a "DoOnce" script variable for the creation kit?

:ermm:
User avatar
jessica Villacis
 
Posts: 3385
Joined: Tue Jan 23, 2007 2:03 pm

Post » Mon Jun 18, 2012 3:13 pm

I've done literally no scripting yet, but I would assume that would be the same? Declare a variable, then set the variable when the action occurs so it can only occur once?
User avatar
Claire Vaux
 
Posts: 3485
Joined: Sun Aug 06, 2006 6:56 am

Post » Mon Jun 18, 2012 1:51 pm

You can put code you want to only happen once in the OnInit event of a script attached to a quest with "Run Once" checked on the quest's initial tab.
User avatar
claire ley
 
Posts: 3454
Joined: Fri Aug 04, 2006 7:48 pm

Post » Tue Jun 19, 2012 2:38 am

You can put code you want to only happen once in the OnInit event of a script attached to a quest with "Run Once" checked on the quest's initial tab.

Not using a quest script, this script is attached to a weapon.

Some examples of scripts that would use the "do once" variable would help.

:biggrin:
User avatar
Lucie H
 
Posts: 3276
Joined: Tue Mar 13, 2007 11:46 pm

Post » Mon Jun 18, 2012 2:50 pm

I've done literally no scripting yet, but I would assume that would be the same? Declare a variable, then set the variable when the action occurs so it can only occur once?

Nope they have been changed as far as I know.
User avatar
michael flanigan
 
Posts: 3449
Joined: Thu Jun 14, 2007 2:33 pm

Post » Tue Jun 19, 2012 12:57 am

I know of RegisterForSingleUpdate() but... if you aren't using a Quest script, that probably isn't necessary.

Could you just use a single variable and a conditional statement to handle this?

int iDoOnceif !iDoOnce     ;do stuff here     iDoOnce = 1endif
User avatar
Elena Alina
 
Posts: 3415
Joined: Sun Apr 01, 2007 7:24 am

Post » Mon Jun 18, 2012 3:24 pm

I know of RegisterForSingleUpdate() but... if you aren't using a Quest script, that probably isn't necessary.

Could you just use a single variable and a conditional statement to handle this?

int iDoOnceif !iDoOnce	 ;do stuff here	 iDoOnce = 1endif

That's what I'd do. Just have to set it to 0 initially, and you're good to go.
User avatar
Noraima Vega
 
Posts: 3467
Joined: Wed Jun 06, 2007 7:28 am

Post » Tue Jun 19, 2012 12:44 am

"DoOnce" type variables were never special, so it doesn't make much sense to ask "is there a DoOnce variable". As always, you can just define your own.

Something new that's been added in Papyrus that can be used in place of DoOnce variables (and make other things cleaner too) is states. For example:
Event OnInit()	; Do stuff	Debug.Notification("Stuff has been done")	GotoState("Done")EndEventState Done	; Nothing happens in this stateEndState
In that example, the state isn't actually necessary because the http://www.creationkit.com/OnInit event wouldn't run again until the object is reset, at which point the state also gets reset, but if you were to add more stuff to the script, like other events, that shouldn't be called in the "Done" state then it would be appropriate.

Here's what the wiki has to say about States:
  • http://www.creationkit.com/States_(Papyrus)
  • http://www.creationkit.com/Using_States_In_Papyrus
  • http://www.creationkit.com/State_Reference
Cipscis

EDIT:

In relation to above posts, we now have proper "bool" types, so it's more semantically correct to use such a variable for a "DoOnce" variable:
bool bDoOnce = falseif !bDoOnce         ;do stuff here         bDoOnce = trueendif

Cipscis
User avatar
Shannon Marie Jones
 
Posts: 3391
Joined: Sun Nov 12, 2006 3:19 pm

Post » Mon Jun 18, 2012 1:19 pm

In relation to above posts, we now have proper "bool" types, so it's more semantically correct to use such a variable for a "DoOnce" variable:
bool bDoOnce = falseif !bDoOnce		 ;do stuff here		 bDoOnce = trueendif

Cipscis

Yes, excellent point

It's difficult to break ALL of the old habits ;)
User avatar
carrie roche
 
Posts: 3527
Joined: Mon Jul 17, 2006 7:18 pm

Post » Tue Jun 19, 2012 4:10 am

That's what I'd do. Just have to set it to 0 initially, and you're good to go.

Cheers for the advice works perfectly (even when dropping the wep and picking it up the script variable is still saved as far as I can tell).

Good advice from Cipscis also (old habits die hard).
User avatar
Steven Hardman
 
Posts: 3323
Joined: Sun Jun 10, 2007 5:12 pm


Return to V - Skyrim