javascript - error when loading a saved game -
i've create puzzle game yesterday , i've made save system, i'm getting error when loading save:
here's function gets launched when loading save:
function loadsave(){ var savedata = $("#savetext").text(); var piecedata = savedata.split("|"); var posdata = []; var puzzleinfo = piecedata[0].split(","); creategrid(parseint(puzzleinfo[1])); createpieces(parseint(puzzleinfo[1]), puzzleinfo[0]); oldsource = imgsource; imgsource = puzzleinfo[0]; console.log(savedata); $("#puzzlecontainer img").attr("src", imgsource); for(i=1; < pieceamount+1; i++){ posdata = piecedata[i].split(";"); $(".piece:nth-child("+i+")").css({ top: posdata[0], left: posdata[1], }); } $( "#pieceamount" ).slider({ value: puzzleinfo[1], }); $("#pieceamountvalue").html(puzzleinfo[1]*puzzleinfo[1]); }
after bit of troubleshooting, i've found out puzzleinfo[0] nothing in it
does knows why src i'm getting save empty?
edit:
here's function launches when error detected:
$("#puzzlecontainer img").error(function(){ imgsource = oldsource; creategrid(size); createpieces(size, imgsource); $("#puzzlecontainer img").attr("src", imgsource); alert("the image not found, link correct?"); });
i've figured out wrong
the problem here:
var savedata = $("#savetext").text();
savedata empty, needed value using
var savedata = $("#savetext").val();
instead
Comments
Post a Comment