[SCRIPT] Adding delay to for-loop - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html) +---- Thread: [SCRIPT] Adding delay to for-loop (/thread-27105.html) |
Adding delay to for-loop - Neelke - 11-05-2014 So I made this custom function that allows me to turn off spider eggs and spiders by writing in int parameters. Code: string gNameOfSpiderEggs = "organic_spider_egg_small_"; Now what I want to add in, is a slight delay for the for-loop. For example, first spider spawn immediately, then after 1 second next one spawn, then after 0.5 seconds next one spawn and etc. I tried using a while loop, but it just froze my game. Is there a way of doing this another way? Or is there an actual way to do it with the while loop? Sidenote: The particle system crashes the game. Reason its //. RE: Adding delay to for-loop - Mudbill - 11-05-2014 Why use a for-loop? How about a timer loop? PHP Code: int count = 0; A for-loop will repeat the same action for a certain amount of times. It would work if Amnesia had any form of Thread.sleep(); function, but it does not as far as I'm aware of. A while-loop crashes you because it loops infinitely as long as the boolean question is accepted. This Timer-loop is basically just an infintely looping timer. It repeats with a random delay to each iteration. Some of the variables I used can be replaced by the function versions (by that I mean the SetLocalVarInt instead of primitive int) if you prefer those. To start the loop, just call PHP Code: TimerLoop("loop"); PHP Code: RemoveTimer("loop"); You can add further checks to it so that it will only repeat for your specified Min and Max amounts, but those are simple if-statements. You can probably figure out what needs tweaking. RE: Adding delay to for-loop - burge4150 - 11-06-2014 Can also just have the function call itself from within itself (recursive I think it's called?) with a timer. Use an IF statement to check when it no longer needs to call itself. RE: Adding delay to for-loop - Neelke - 11-06-2014 Considering I have around 20 spider eggs or something in this level, it would make the script quite long eventually. So I'm simplifying it this way. But either way, I got it working just recently. So I used Mudbill's suggestion with adding in a timer to control the spawning functions easier. Code: string gNameOfSpiderEggs = "organic_spider_egg_small_"; Either way, Mudbill solved most things. Thanks guys. |