[solved] leaving for-loop after first turn - where is my mistake

Posted By: Ditje

[solved] leaving for-loop after first turn - where is my mistake - 08/09/10 09:36

I can`t see the wood because of the trees (german adage) grin

Following statement doesn`t work, beacuse enemy_distance get not counted up. But I don`t know why. There must be a very basic mistake in my thoughts.

Ditje

Code:
...
var enemy_distance = 2;
...
// Welle 1
var i;
for(i=1; i<9; i++)
{
   if(enemy_distance >= 2) 
   {
      if(i %2 == 0) 
      {
         enemy[i] = ent_create("bee2.mdl", vector(-50, 1000, 500), start_bee_wave1); 
         enemy_distance = 0;
      }
      else 
      {
         enemy[i] = ent_create("bee1.mdl", vector(-50, 1000, 500), start_bee_wave1);
         enemy_distance = 0;
      }
   }
   else enemy_distance += time_step;
}
...
wait(1);
...



Edit: if I remove wait(1) - I get entities until crash.

I create more entities by this loops(9-40). The ent_create functions of this entities don`t call a function yet and their loops work fine.

Code:
for(i=9; i<17; i++)
{
   if(i %2 == 0) enemy[i] = ent_create("bee2.mdl", vector(epos[i][0], -epos[i][1], epos[i][2]), NULL); 
   else ent_create("capture.mdl", vector(epos[i][0], -epos[i][1], epos[i][2]), NULL);
}


Posted By: Lukas

Re: leaving for-loop after first turn - where is my mistake? - 08/09/10 12:34

I guess the problem must be in the actions of your entities.
Posted By: EvilSOB

Re: leaving for-loop after first turn - where is my mistake? - 08/09/10 13:54

What is it you are "trying" to do?
This broken code makes no sense to me.

Why is the "enemy_distance += time_step;" in the "else" section?
Because of this, and the "var enemy_distance = 2;",
enemy_distance never get incremented, because the "else" never gets triggered.
Posted By: Ditje

Re: leaving for-loop after first turn - where is my mistake? - 08/10/10 08:48

Why should else not get triggered? When I create create an ENTITY enemy_distance gets set to 0 and 0 is smaller than 2 wink

But I am proud to annouce that I found a solution and reached my target. laugh Code for creating all enemies is now decreased from 138 lines to 45 lines.

Thanks an cheers

Ditje
Posted By: EvilSOB

Re: leaving for-loop after first turn - where is my mistake? - 08/10/10 11:56

Doh! Sorry. My bad. Was too tired and missed the obvious.

Good work on finding it yourself!
© 2024 lite-C Forums