I've made a function which gets invoked each time when values of my sliders were being changed. The problem consists in that this function generates an array which later it passes to other functions. So far, so good but sliders may be adjusted аs many times the user wants to and as I said, this triggers the function which generates an array, which means that I can get hundreds or even thousands of arrays while I need actually the last one. Here is my code:
function tg() {
$(".dot").remove();
var p, x, y, xo, yo, agl, spd, g, t = 1, isin2, angle1, n = 0, i = 1;
var m = [];
p = $("#ba").position();
xo = p.left;
yo = p.top;
spd = $("#spd").val();
agl = $("#agl").val();
g = $("#g").val();
angle1 = formula;
isin2 = true;
while (isin2) {
y = formula;
x = formula;
m.push([x, y]);
//...
t++;
isin2 = isin(x, y);
}
if (isin2 == false) {
$(".dot").last().remove();
m.pop([x, y]);
console.log(m);
}
activate(m);
}
There come the sliders, I've actually given just one of them because the rest two are absolute copies, they're just addressing other variables.
$(document).ready(function(){
$("#slagl").slider({
min:0,
max:89,
value:15,
range:"min",
slide: function(event, ui){
$("#agl").val(ui.value);
tg();
}
});
As you can easily see it just piles new and new arrays without cleaning the others. The goal is to delete somehow all the others redundant arrays, made on slide and leave only the last one, each time the function is called.