So I am writing some code sections here and there for a game I'm trying to devellope and I have written a piece to cause an action when a condition is met, however the action loops infinitely once the condition is met. I need it to only trigger once per condition met or to ask it to only run once?
Sorry I am a supreme novice and still learning, only started a couple weeks ago with Java script.
More in depth..
The condition is met when IE: target A "Hits" target B.
Then the below piece executes and prompts target A to use skill X, but this also counts as a "Hit" and causes the condition to be met again and thus infinite loop.
Please how do I stop this.. How is it written? Can this be explain in novice terms?
This is what I have.
var skill = 49;
var target = -2;
BattleManager.queueForceAction(user, skill, target);
NOTES: "user" is defined elsewhere
Did I explain this correctly?
What I have tried:
I tried creating and storing a variable to make an if condition of (times <= 1) but may not have written that correctly so it may not have worked right..
This is the block I tried
var times = 0;
var skill = 49;
var target = -2;
if (times < 1) {
BattleManager.queueForceAction(user, skill, target);
times = +1;
}