Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loops?
#1
I didn't realize how easy it was to do AI scripting. You just add a file and then do C programming? Damn if I knew it was that simple (compared to like hex shiiiii~) I would have done it earlier lol

Anyways I have a problem. As you guys may know my DBZ characters can recharge their mana by using DJA A A A A...
I tried to implement this in scripting when they have low MP they wil charge if enemies aren't around.

Code:
int ego(){
if (((target.x-self.x) >= 300) && self.mp < 50) {
  DJA();
  A(1,0);
  }
}

Whatever the MP number I use, they will only charge up to that value. So if they have less than 250 mp they will only charge till they hit 250.

Code:
int ego(){
if (((target.x-self.x) >= 300) && self.mp < 50) {
  DJA();
  if (self.mp < 500) {
    A(1,0);
  }
  else {
  A(0,0);
  }
}

I tried this and it didn't work either if I recall.

So, are there loops available to use like while loop? Or are the only conditions available if statements?
Thanks!

Basically I want them to recharge their ki (mana) when enemies are far away and their mp is low and they stop when they hit 500 or an enemy draws near.

ALSO! The AI charge like 3x faster than humans, they press that attack button really fast!!!!!!!!!!!!!!!!!!!!!
Reply
Thanks given by:
#2
I know for sure that a for-loop exists (click me, yo).

According to the list of supported commands,
    AI-Code:
while
is implemented. You might want to give it a shot.

Not entirely sure though, that they ai will then actually perform this move, considering it'll probably need several frames to do that. The ego()-function is executed every frame again. Does AI-scripting have custom variables that last longer than a frame by now? Haven't programmed AI for so long that I forgot everything, haha.
Silverthorn / Blue Phoenix
~ Breaking LFE since 2008 ~

"Freeze, you're under vrest!" - Mark, probably.

» Gallery | » Sprites | » DeviantArt
Reply
Thanks given by:
#3
While is totally not the thing you are looking for here because your AI script runs once each frame of the game. You cannot stop or loop inside it over several frames - it will always start from the top.
(in fact the ego() function is called by the main AI that moves the character around - when moving away from a downed opponent or walking towards an item etc the basic AI will not try to perform special moves and thus not call ego())

The thing to do here is using two conditionals:
One to start the charge (performs DJA)
and one to hold the charge (performs A).

Only use loops if you ever need to check through several objects quickly (to manually find a threat or target).

If you are having trouble getting the two different conditions together: imagine scripting the input for Davis' continuous D>A+A+... - how would you do it?
Reply
Thanks given by:
#4
the problem is that the outer if function limits it to 50 mp or whatever you set.

the solution would be to use a condition.
    AI-Code:
int ego(){ 
if (((target.x-self.x) >= 300) && self.mp < 50 && charging=false) {
  charging=true;
  DJA();
  }
 
if(charging) { 
  if(self.mp >=500 || (target.x-self.x) < 300) ) {
    charging=false;
  }
  A(1,0);
  }
 
}

i think this should work.
i don't know if you need to define or create this condition somewhere first (never actually did AI programming).
Reply
Thanks given by:
#5
(05-07-2014, 07:51 PM)Bamboori Wrote:  i think this should work.
i don't know if you need to define or create this condition somewhere first (never actually did AI programming).
You have to define it first, but values don't carry over from one frame to the next (it'll get redefined).
The only solution to that is defining a global one outside of the ego() function - however that'll be used by all objects. You can again get around that by turning it into an array and only using one slot per object, but that's highly inefficient.

The easier solution is to drill down and see what actually yields true while charging (or shooting or leaping or any other combo thing): self.frame.
Reply
Thanks given by:
#6
"While" doesn't help you at all (I mean you're trying to make the computer click slower, how will using more looping going to fix this?). One of the problems in your code is that you're not checking the distance properly. Simply using "(target.x-self.x)" to check for a distance can return a negative number if the opponent is at your left; which would still evaluate to false even if the opponent is actually farther than you intended:
[Image: B3rC4nf.png]
Solution there is to use the "abs()" function. It returns the absolute value of a number.

Another problem, which is why the opponent isn't charging, is that you've wanted that "charging" variable to be set once and for all. As the other guys has mentioned, every variable is reset every frame. Best solution is to make use of the .frame instance to have continuing the charging depends on the number of the frame instead. ".frame" can also help you with the fast charging problem too; consider having the clicks dependent on the number of the frame as well.
[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: 5 Guest(s)