Help! Get map data array

Discussion in 'Learning Javascript' started by Skotty TV, Oct 20, 2016.

  1. Skotty TV

    Skotty TV Veteran Veteran

    Messages:
    98
    Likes Received:
    160
    Location:
    Germany
    First Language:
    German, English
    Hi There!


    I just want to know if anyone (good scripter) can help me out.


    I want to create a new array with all map info stored in ->


    - var array = [];


    - array[1] = Map001.json


    something like this...


    The thing is, in $datamap is always just the last map stored. And $dataMapInfos doesnt have all infos i need.


    I need the "note" information of each map.


    Basicly i just need a new array where all "Map00x.json" objects are stored in.


    - DataManager._databaseFiles.push({name: "$datamap1", src: "Map001.json"});


    <- This is not a solution because at that point the length of $dataMapInfos is not given,


    so a "for loop" has to go up to 999 which will give the error "Map00X is not found".... :(


    Help!


    The final array should look like this:


    $myarray[]


    - 0: Map001


           - data


    - 1: Map002


           - data


     2: ....
     
    Last edited by a moderator: Oct 20, 2016
    #1
  2. Andar

    Andar Veteran Veteran

    Messages:
    28,116
    Likes Received:
    6,369
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    I think you better tell us what you want to do - so far you only told us how you want to do something, not what and why.


    Because unfortunaly, storing the entire map-jsons will require a lot of memory, and you won't need 99% of all that data.


    So better to tell us what you want to do, because then we might be able to point you to another way that stores only the minimum info you need.


    Because there are a lot of reasons why only one map is loaded...
     
    #2
  3. Skotty TV

    Skotty TV Veteran Veteran

    Messages:
    98
    Likes Received:
    160
    Location:
    Germany
    First Language:
    German, English


    First of all thanks for the quick awnser!


    I dont want to store all of it of course... i just want to create an array with all maps noteboxes.


    The Plugin i want to create will handle some sort of "Level Selection".


    I want to determine the "Chapter" of a map with <Chapter: X> in the Maps Notebox


    and the "Level" with <Level: X>.


    Another part will be if the Level/Chapter is: Revealed, finished, hidden... etc.


    thats why i need to create a new array that will get saved inside a savegame file.


    Telling here what the script is for and what it will do exactly would be kinda dumb, i hope you´re with me.


    The final array should (now) look like this:


    $myarray[]


    - 0: Map001


           - note


    - 1: Map002


           - note


    - 2: ....


    How to read a JSON file proper will might be all help i need ->


    for (var i = 1; i < $dataMapInfos.length; i++) {


    ****var tmp = read Json Map(i).note****


          mylist.push(tmp);


            }


    ...i dunno :(
     
    #3
  4. Lantiz

    Lantiz Biterkid Veteran

    Messages:
    719
    Likes Received:
    1,064
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    For loading a json from the data directory:


    function loadData(filename) {
    var fs = require('fs');
    var dir = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/');

    if (dir.match(/^\/([A-Z]\:)/)) {
    dir = dir.slice(1);
    }

    filename = decodeURIComponent(dir) + 'data/' + filename + '.json';

    return JsonEx.parse(fs.readFileSync(filename, 'utf8'));
    };




    Wonder how will that be if you use like 200 maps xD
     
    Last edited by a moderator: Oct 20, 2016
    #4
    Skotty TV likes this.
  5. Skotty TV

    Skotty TV Veteran Veteran

    Messages:
    98
    Likes Received:
    160
    Location:
    Germany
    First Language:
    German, English


    Nice!


    Thank you a lot! BD


    Works fine!


    Btw: Tested now with 150 maps.... (whole map.json data!)


    2-3 Seconds to load game, 138-142 FPS.


    So everything is ok :D


    You will get credited for your help!


    I will send you a private massage as soon the plugin is finished.


    This can be closed.
     
    Last edited by a moderator: Oct 21, 2016
    #5
    Lantiz likes this.
  6. Lantiz

    Lantiz Biterkid Veteran

    Messages:
    719
    Likes Received:
    1,064
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    Awesome!


    Glad I could help, you don't need to worry about credtis [:


    I'll wait the message tho.


    Be cautious about that speed, maybe it's fast because your machine is fast. I guess It's always nice to think about the budget players.


    Cheers!
     
    #6
    Skotty TV likes this.

Share This Page