Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Object not on the map
#1
I want my character to make an attack (e.g. ball) only if it's not on the map already or if it's far enough for him.
Code:
for (int i = 0; i < 100; ++i) { //darkness if (loadTarget(i)==-1 && target.id==448 && target.team==self.team && abs(self.x-target.x)<500) { DdA(); } }
Something like this works only when a teammate do the same attack and it's gone or far enough, but I want him to make it alone.
Reply
Thanks given by:
#2
Dude, that's not how you're supposed to do it XD. Whenever you write such a code try to run it in your head. For instance:
You're looping on the first 100 objects (although you're supposed to loop on 399 since THAT is the maximum number of the objects you can have on the screen) and assigning the index to the variable i. Every loop, you check if that target doesn't exist AND if its ID equals 448. That's like checking if you don't have a cake, and if you don't, you check what color it is; it doesn't exist in the first place!!? So how can you check a property or something that doesn't exist? The right thing you should do is:
    AI-Code:
bool theballexists=false;  //we first start by defining our variable 
for (int i=0; i<399; ++i){    /*we're checking if that ball exists, if it does, we set the variable to true. Else,
                                       it just means that the ball doesn't exist and "theballexists" stays false*/
    if (loadTarget(i)==0 && target.id==448  && target.team==self.team && abs(self.x-target.x)<500){
        theballexists=true;
    }
}
if (!theballexists){   //note that it is the same as saying (theballexists==false)
    DdA();             //if our ball doesn't exist, we do the move.
}


[Image: signature.png]
A-Engine: A new beat em up game engine inspired by LF2. Coming soon

A-Engine Dev Blog - Update #8: Timeout

Reply
Thanks given by: pikol
#3
Ok, I'll keep that in mind.

But it doesn't work either. He just keep spamming with this attack, bacause "theballexists" is always false, just like he would ignore the "if" in the loop.

Ok, it should be loadTarget(i)==3 and it's alright then. Thanks a lot :)
Reply
Thanks given by:
#4
(05-13-2014, 03:33 PM)pikol Wrote:  Ok, I'll keep that in mind.

But it doesn't work either. He just keep spamming with this attack, bacause "theballexists" is always false, just like he would ignore the "if" in the loop.
OOps. Yes my bad. The range conditioning check must've been in the if the ball exist condition as well:
    AI-Code:
bool theballexists=false;  //we first start by defining our variable 
for (int i=0; i<399; ++i){    /*we're checking if that ball exists, if it does, we set the variable to true. Else,
                                       it just means that the ball doesn't exist and "theballexists" stays false*/
    if (loadTarget(i)==0 && target.id==448  && target.team==self.team){
        theballexists=true;
    }
}
if (!theballexists && abs(self.x-target.x)<500){   //note that it is the same as saying (theballexists==false)
    DdA();             //if our ball doesn't exist, we do the move.
}

[Image: signature.png]
A-Engine: A new beat em up game engine inspired by LF2. Coming soon

A-Engine Dev Blog - Update #8: Timeout

Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)