05-08-2014, 09:52 AM
"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.
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.
A-Engine: A new beat em up game engine inspired by LF2. Coming soon
A-Engine Dev Blog - Update #8: Timeout