0

I created a function that loads game map from json file.

function newTileMapFromJSON(src) {
    var mymap;
    $.getJSON(src, function(data) {

        [...]

        var finalData = {
            map: tMap,
            tiles: blocks,
            name: MapName
        };

        return finalData;
    });
}

But it won't work. There is "return" but in function inside "getJSON". I've no idea how to get "finalData" and return it.

function newTileMapFromJSON(src) {
    var mymap;
    var finalData;
    $.getJSON(src, function(data) {

        [...]

        var finalData = {
            map: tMap,
            tiles: blocks,
            name: MapName
        };

    });
    return finalData;
}

This code doesn't work, returned finalData is undefined. Maybe getJSON works in another thread? I don't know.

How would you do that, if you were me?

4

0 回答 0