Getting a script to run only once

Post » Thu Feb 04, 2016 4:30 am

AKA infinite message boxes of doom



I have a script that is supposed to run once, disable a unique static (luce_in_c_plain_room_side), give me a notification and then stop running. It disables the static just fine, but then continues to run and give me infinite message boxes.



My reading of this script is that the marker variable is set, the if tests as true, it ups the variable so that it won't run again, the static is disabled, I get a messagebox, and then the script should either end or at least not do anything ever again. Clearly that's not what's happening.



Any ideas on where I'm going wrong?



begin luce_stavpatchdisable

short doOnce

set doOnce to 1

if ( doOnce == 1 )
set doOnce to 2
luce_in_c_plain_room_side -> Disable
MessageBox "Disabled"
endif

end luce_stavpatchdisable
User avatar
Tracey Duncan
 
Posts: 3299
Joined: Wed Apr 18, 2007 9:32 am

Post » Wed Feb 03, 2016 2:26 pm

Might I suggest reading Morrowind Scripting for Dummies 9.0. There are many good examples in there.



For your particular case, you should use the fact that variables are initialized to 0.


Remove the 1st set doOnce.


Change the if statement to:


If ( doOnce == 0)



That should work.

User avatar
Melanie
 
Posts: 3448
Joined: Tue Dec 26, 2006 4:54 pm

Post » Wed Feb 03, 2016 1:37 pm

Blah. All that time desperately trying different combinations of the same script, and it was that simple the whole time? :facepalm:



I have been reading through MWFD, but I got nervous that maybe it might not initialise at 0, so I initially tried setting doOnce to 0 manually ... and then started changing the numbers around just in case, never thinking that it might be that the statement was there at all that was the problem. Oh well.



Thanks for the help, it works perfectly now!

User avatar
GRAEME
 
Posts: 3363
Joined: Sat May 19, 2007 2:48 am


Return to III - Morrowind