jquery - Javascript issue with mathematical equations -


Before I start, I can see you in this post that possibly the abundance of code you have made Apologize for This is the most annoying bug I've ever tried to fix. I am working for hours, and I still have not got anything.

I have two javascript variables, one name, addfood and named click .

The first task ( addBPS ) takes the variables from the code to addfood and click and this amount is re- Assign once again the variable click .

The next part of the function is counted just one aviation in a div. It reads the number in the div, and it is animated to "new numbers" in "Variables" in variable clicks . add after the function runs if statement function when variable addfood is greater than zero This function runs addBPS every second Finally, defines a variable named if statement first and sets it to the right.

The next function (which is executed when a button is clicked), reassign the variable addfood and whatever number adds Was (variables in the function).

The next line is something similar, and simply reassign variable variable click and whatever number cost (variables in the function) Reduces

The last statement, which I believe, is very self explanatory. All this does this function runs addBPS if the variable addfood is greater than zero then it will be used for setInterval function addBPS If the variable is not equal to first equality (variable first can also be used on line1.)

 < Code> var addfood = 5; Var click = 123; Function addBPS () {click = number (click) + number (addition); Antim ({countNum: number (click)}, {duration: 1000, simplicity: 'linear', phase: function () {$ ('# current'). Text ((Math.floor (this.countNum)); },}); } If (number (plus)> gt; {] (addBPS); Set internwall (ADBPS, 1000); Var first = true; } Function upgrade gam (id, level, cost, add, user) {addfood = number (plus) + number (addition); Click = number (click) - cost; If (number (plus) and gt; 0) {addBPS (); If (first! = True) {set intervals (edbs, 1000); }}}  

So now the situation where the problem occurs ...

The function addBPS is running in every other part, No matter whatsoever. It is considered to be continuously adding the value of every second to addfood to click .

If the value of addfood is at least one, the code works perfectly however, when the value of addfood is zero, and then if I change the variable and make it one by one (using a button), instead it is added by addfood to click , and every time, Price class of addfood .

Example:

Default:

addfood = 0;
var click = 0;

Addfood to one :

addfood = 1;
Click (after 1 second) = 1;

Add addfood to :

addfood = 2;
Clicks (after 1 second) = 4;

Add <3> Addfood to <3>

addfood = 3;
Clicks (after 1 second) = 9;

What do I need:

default:

addfood = 0;
var click = 0;

Add one addfood :

addfood = 1;
Click (after 1 second) = 1;

Add to two addfood :

addfood = 2;
Miscellaneous Clicks (after 1 second) = 2;

Add to addfood to three

addfood = 3;
Miscellaneous Clicks (after 1 second) = 3;

However, as I said, if the initial value of addfood is the same, the code works fine when it is zero, and then I can use the Addfood changes the value, then the estimated value is squared. Why is this happening?

Every time the upgradeGame () is called, a new interval will be created. So after the first click, it will be called only once. After the second click, it will be called twice, etc. To solve this, you must include

  first = true;  

Such:

  function upgradeGame (id, level, cost, add, user) {addfood = number (plus) + number (plus); Click = number (click) - cost; If (number (plus) and gt; 0) {addBPS (); If (first! = True) {set intervals (edbs, 1000); First true =; }}}  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -