Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to determine when for-loop is done
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#11
RE: How to determine when for-loop is done

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: (Select All)
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: (Select All)
if(iEnemy == -1)
    {
        
AddDebugMessage("ENEMY NOT FOUND"false);
        return;
    } 
...ignores this spawn.

Trying is the first step to success.
06-16-2015, 02:36 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#12
RE: How to determine when for-loop is done

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.

(This post was last modified: 06-19-2015, 08:05 AM by Mudbill.)
06-16-2015, 02:55 PM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#13
RE: How to determine when for-loop is done

(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

Discord: Romulator#0001
[Image: 3f6f01a904.png]
06-16-2015, 02:58 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#14
RE: How to determine when for-loop is done

(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!






Trying is the first step to success.
06-16-2015, 03:15 PM
Find
7heDubz Offline
Posting Freak

Posts: 1,329
Threads: 40
Joined: Feb 2013
Reputation: 41
#15
RE: How to determine when for-loop is done

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)

06-16-2015, 03:42 PM
Find
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#16
RE: How to determine when for-loop is done

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

Cool Big Grin
06-17-2015, 10:40 AM
Find




Users browsing this thread: 2 Guest(s)