views:

182

answers:

5

I am making a game using lite-C (exactly same syntax as C). and I cannot make this loop work. It gives me an error at this line at compilation.
for(int i = 0; i < (cantenemigu * 3); i += 3)

I have an array with the information of where to create the enemies. the array contains the x,y,z coordinates.
cantenemigu is the amount of enemies that there are in the array.

With this loop I would get the information of each enemy and create it.

[EDIT] The answers didn't work. I added the ; acsidently while writing the post.

Maybe the problem is somewhere else;

Here is the hole part.

int cantenemigu = 3;
var posenemigu[] = {-900, 550, -10, -1100, 1600, -10, 70, 1680, 20};
void load_enemigunan()
{ 
 for(int i = 0; i < (cantenemigu * 3); i += 3) 
 {
  ent_create("targetr.mdl",vector(posenemigu[i],
             posenemigu[i + 1],
             posenemigu[i + 2]),NULL);
 } 
}

This is the code if I don't add the <br>

I solved it.

this worked.

int i
for(i = 0; i < 3*cantenemigu; i += 3)
{
    ent_create("targetr.mdl",vector(posenemigu[i],
                                                posenemigu[i + 1],
                                                posenemigu[i + 2]),NULL);
}

In C# it doesn't have be declared before. I assumed it was also so in C. (or maybe it's a bug in the compiler).

+7  A: 

for (int i = 0; i < (cantenemigu * 3); i += 3)

There should not be any ; after i += 3.

Bang Dao
+2  A: 

Get rid of the 3rd ;.

for(int i = 0; i < (cantenemigu * 3); i += 3) 
thyrgle
A: 
for(int i = 0; i < (cantenemigu * 3); i += 3;) 

What is the error? That last semicolon shouldn't be there.

What is the body of the loop?

What type of variable is cantenemigu? Can it be coerced to int?

alex
I really hope `cantenemigu` is a domain specific term because it looks like gibberish to me.
ChaosPandion
@ChaosPandion I speak papiamentu. It stands for cantidad di enemigu (amount of enemies).
Aaron de Windt
+1  A: 

It looks like you are missing a closing parenthesis for your call to vector.

ent_create(
    "targetr.mdl",
    vector(
        posenemigu[i], 
        posenemigu[i + 1], 
        posenemigu[i + 2],
        NULL
);
ChaosPandion
yes I mis it. thanks. But the error still continues.
Aaron de Windt
@Aaron - Please post the exact error the compiler is giving you.
ChaosPandion
+2  A: 

Try changing your code to this: (note what I've done is move the declaration of i outside the for loop.

int cantenemigu = 3;
var posenemigu[] = {-900, 550, -10, -1100, 1600, -10, 70, 1680, 20};
void load_enemigunan(){ 
    int i;
    for(i = 0; i < (cantenemigu * 3); i += 3){
         ent_create("targetr.mdl",vector(posenemigu[i],
             posenemigu[i + 1],
             posenemigu[i + 2]),NULL);
     } 
}
Mark E
You posted it just 5 min to late. This solved the problem. Is it a compiler bug?
Aaron de Windt
@Aaron, no, this isn't a compiler bug, it's standard C syntax (not C99 syntax which would allow what you originally wrote). FWIW, if this solved the problem the etiquette here is to accept the answer.
Mark E
yes I know. sorry. I don't talk english. sorry if it sounded bad. thanks for the answer. Wath I wanted to say is that I just solved it the same way.
Aaron de Windt
@Mark: C99 is standard C. It's just that many implementations don't conform to modern standards.
R..
@R what I meant was it was C90, as opposed to C99...what gcc, for instance will call just plain "C".
Mark E