Frictional Games Forum (read-only)
How to determine when for-loop is done - 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: How to determine when for-loop is done (/thread-30128.html)

Pages: 1 2


RE: How to determine when for-loop is done - FlawlessHappiness - 06-16-2015

Thank you for the explanation Cthulu!
I already knew about for-loops in general, but extra knowledge is always good.

I used the help I got to create this script:
PHP Code:
int Spawn_PickUnusedNumber(string &in asNameint alFromint alTo)
{
    
int Start RandInt(alFrom,alTo);
    
int End alTo;
    
    for(
int i=Start;i<=End;i++)
    {
        if(
GetLocalVarInt(asName+i) == 0)
        {
            return 
int(i);
        }
    }
    
    return 
int(-1);


The idea is, I have a set of enemies. When one is spawned it's variable is set to 1. This is so that it cannot be picked while it is already active.

This Spawn_PickUnusedNumber helps me pick a number that isn't already used. If all numbers are used it'll set the number to -1, and thus...
PHP Code:
if(iEnemy == -1)
    {
        
AddDebugMessage("ENEMY NOT FOUND"false);
        return;
    } 
...ignores this spawn.


RE: How to determine when for-loop is done - Mudbill - 06-16-2015

So you're using a dynamic indexing system? It will, on-the-run, assign a number to an enemy spawned whenever they are, and check if the number is in use? You might also have a script which removes an enemy, and thus clears its index value, making it available for the next enemy?

Dunno what it is used for, but I can see why it would be useful. Indexes are super helpful.


RE: How to determine when for-loop is done - Romulator - 06-16-2015

(06-16-2015, 02:55 PM)Mudbill Wrote: Dunno what it is used for, but I can see why it would be useful. Indexes are super helpful.

Oh believe me, you'll be amazed at what it is used for... Wink


RE: How to determine when for-loop is done - FlawlessHappiness - 06-16-2015

(06-16-2015, 02:55 PM)Mudbill Wrote: Dunno what it is used for, but I can see why it would be useful. Indexes are super helpful.

A concept.
Spoiler below!








RE: How to determine when for-loop is done - 7heDubz - 06-16-2015

All code written out in word format is read top to bottom. Exactly in that order.

If you go into a for loop it'll loop through and stay right in that segment of code until broken out of,
if a while loop it'll stay just in that code until it's broken out of.
(instead of a node based for example which would read be left -> right)


RE: How to determine when for-loop is done - TheGreatCthulhu - 06-17-2015

(06-16-2015, 03:15 PM)FlawlessHappiness Wrote: A concept.

Cool Big Grin