hi i got the problem the script.js gives me
<div id="gracze">
<div id="10" class="char" style="z-index: 19; top: 592px; left: 608px; "></div>
<div id="14" class="char" style="z-index: 25; top: 784px; left: 608px; "></div>
</div>
instead
<div id="gracze">
<div id="4" class="char" ... ></div>
<div id="10" class="char" style="z-index: 19; top: 592px; left: 608px; "></div>
<div id="14" class="char" style="z-index: 25; top: 784px; left: 608px; "></div>
</div>
get_players.php
4/62/6
10/19/19
14/19/25
script.js
function get_players()
{
$.ajax({
type: "POST",
url: "get_players.php",
dataType: "html",
success: function(data) {
var str = data;
var chars = str.split("<br />");
var lol = chars.length;
for(var i = lol; i--; ) {
chars[i] = chars[i].split('/');
var o = document.getElementById(chars[i][0]);
var aimt = i;
if (!o) {
if (aimt!=chars.length-1 && aimt != 0) {
$('#gracze').html('<div id="'+chars[aimt][0]+'" class="char"></div>'+$('#gracze').html());
$('#'+chars[aimt][0]).css("top", chars[aimt][2]*32-16+"px");
$('#'+chars[aimt][0]).css("left", chars[aimt][1]*32+"px");
$('#'+chars[aimt][0]).css("z-index", chars[aimt][1]*32);
}
} else {
$('#'+chars[aimt][0]).animate({
"top": chars[aimt][2]*32-16+"px", "left": chars[aimt][1]*32+"px"
}, { duration: 275});
//$('#'+chars[aimt][0]).css("top", chars[aimt][1]*32-16+"px");
//$('#'+chars[aimt][0]).css("left", chars[aimt][2]*32+"px");
$('#'+chars[aimt][0]).css("z-index", chars[aimt][2]);
}
}
}});
setTimeout("get_players();", 1000);
}
I think it’s because of for(var i = lol; i--; ) {
Change the loop to this:
Javascript array indexes start with 0 and end with the size of the array -1 (so if an array has 5 elements, the first one will have index of 0 and the last one of 4).
Your original loop starts with the size of the array, immediately decrementing it (so the last element is accessed). The loop continues until the variable decrements to 0, at which point the loop is existed, without the first element being used.
See this page about looping over arrays in javascript.
Additionally, this condition
if (aimt!=chars.length-1 && aimt != 0)specifically excludes the last element. Remove the&& aimt != 0.