Jump to content
The Dark Mod Forums

How do I exit while loop script timer?


Fidcal

Recommended Posts

can you please post the full script file here, so it's easier to find your mistake?

FM's: Builder Roads, Old Habits, Old Habits Rebuild

Mapping and Scripting: Apples and Peaches

Sculptris Models and Tutorials: Obsttortes Models

My wiki articles: Obstipedia

Texture Blending in DR: DR ASE Blend Exporter

Link to comment
Share on other sites

Because when your sys.wait(1) expires, the first thing the script does is change global from -1 to 0. The "while" statement sees that global equals 0, and it continues operating.

 

To get the loop to exit, either have your separate function set global to -2 or Time.

Link to comment
Share on other sites

Ah - so the 'while loop doesn't immediately exit when untrue but only at the end? Yes, of course, it tests at the end. I did originally set global to -99 to avoid that sort of thing when I was doing a different sort of loop then I somehow changed it to -1. Thanks grayman.

Link to comment
Share on other sites

It actually tests at the beginning of the loop. This allows the loop to detect the very first time through whether it should run at all.

 

To test at the end of the loop, you do this:

 

do
{
 sys.wait(1);
 global++;
} while ( ( global >= 0 ) && ( global < Time ) );

 

This form of the loop allows one instance to run before checking whether to continue;

Link to comment
Share on other sites

What grayman said. The reason why it did not exit for you was due to syncronising issue - the "set to -1" happened randomly at any time during the loop, so it was likely it happens during the 1s wait time.

 

Also, is "Time" a variable in your loop, e.g. it should run until X seconds are over or it is interrupted?

"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." -- George Bernard Shaw (1856 - 1950)

 

"Remember: If the game lets you do it, it's not cheating." -- Xarax

Link to comment
Share on other sites

Strictly speaking, Time should be a constant. I set it to a variable while developing to see what works best. 8 secs seems OK and I'm too lazy to keep checking how to set a constant in doom script which I keep forgetting. ;) Makes little difference to the working but is really for code clarity.

Link to comment
Share on other sites

You can either set a variable:

 

float time; time = 8;

 

(I forgot if "float time = 8; works, sometimes D3 doesn't like that style...)

 

or simple use "8" in the code:

 

while (duration++ < 8)
 {
 sys.wait(1);
 }

 

I usually define a function for such a task and make the time etc. a parameter, so you can call it with different times w/o having to change the code that does the actual work.

"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." -- George Bernard Shaw (1856 - 1950)

 

"Remember: If the game lets you do it, it's not cheating." -- Xarax

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent Status Updates

    • OrbWeaver

      Finally got round to publishing a tutorial on baking normal maps in Blender, since most of the ones we have are inaccessible or years out of date.
      · 0 replies
    • nbohr1more

      The FAQ wiki is almost a proper FAQ now. Probably need to spin-off a bunch of the "remedies" for playing older TDM versions into their own article.
      · 1 reply
    • nbohr1more

      Was checking out old translation packs and decided to fire up TDM 1.07. Rightful Property with sub-20 FPS areas yay! ( same areas run at 180FPS with cranked eye candy on 2.12 )
      · 3 replies
    • taffernicus

      i am so euphoric to see new FMs keep coming out and I am keen to try it out in my leisure time, then suddenly my PC is spouting a couple of S.M.A.R.T errors...
      tbf i cannot afford myself to miss my network emulator image file&progress, important ebooks, hyper-v checkpoint & hyper-v export and the precious thief & TDM gamesaves. Don't fall yourself into & lay your hands on crappy SSD
       
      · 7 replies
    • OrbWeaver

      Does anyone actually use the Normalise button in the Surface inspector? Even after looking at the code I'm not quite sure what it's for.
      · 7 replies
×
×
  • Create New...