Loops? - Printable Version +- Little Fighter Empire - Forums (https://lf-empire.de/forum) +-- Forum: Little Fighter 2 Zone (https://lf-empire.de/forum/forumdisplay.php?fid=7) +--- Forum: AI Scripting (https://lf-empire.de/forum/forumdisplay.php?fid=56) +--- Thread: Loops? (/showthread.php?tid=9203) |
||
Loops? - bashscrazy - 05-07-2014 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(){ 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(){ 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!!!!!!!!!!!!!!!!!!!!! RE: Loops? - Silverthorn - 05-07-2014 I know for sure that a for-loop exists (click me, yo). According to the list of supported commands,
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. RE: Loops? - YinYin - 05-07-2014 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? RE: Loops? - Bamboori - 05-07-2014 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.
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). RE: Loops? - YinYin - 05-07-2014 (05-07-2014, 07:51 PM)Bamboori Wrote: i think this should work.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. RE: Loops? - A-Man - 05-08-2014 "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: 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. |