JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 171 of 171 View original ↗
  1. Robro33 said:
    plugin commands generally aren't intended to be able to parse JS. I haven't checked how Yanfly set those ones up, but seeing as how it has no parameters I doubt it can and is just reading the string for the command.

    you could use script in move routes. you'd need to use a script call to set the self switch, but it should work with a conditional like the way you're trying.
    Since the commands are added to a movement route, it goes through the script command instead of the plugin command.
    The event in question was created from an event spawner so I wasn't sure if the regular script call would work for it, but if (this.x == 19) {$gameSelfSwitches.setValue([this._mapId, this.eventId(), 'C'], true);} seems to be 100% working.
  2. so I'm trying to find a way to access the data of a map not immediately loaded. is that even possible?

    I've found "$dataMap" but based on the documentation, that just seems to be the data for the current map, and "$dataMapInfo" which just seems to reference all the maps I have, presumably let the engine pull up the json file for the map when loaded.

    is there a way I can pull up the "$dataMap" for an unloaded map, so i can check the data in it? (just reading the data, i don't need to write or edit anything)
  3. Jetyl said:
    is there a way I can pull up the "$dataMap" for an unloaded map, so i can check the data in it? (just reading the data, i don't need to write or edit anything)
    Yes, it's possible to read from files. You can't load it into the usual $dataMap variable, so you'd need to manually access the file using e.g. fetch or XHR, rather than RPG Maker MV/Z's core script method DataManager.loadMapData (*_managers.js).

    Note that these methods are asynchronous on the main loop. If you need to block until loaded then you'll need the usual extra structure: check every frame to see if it's done loading, if so then proceed.

    Jetyl said:
    , and "$dataMapInfo" which just seems to reference all the maps I have,
    I don't think the core engine actually uses $dataMapInfos for anything...it stores editor information about the map tree, like the list order and parent-child links.
  4. Okay, that gave me the help i needed, and i now can pull up non-loaded mapdata. however I am now hitting my next hurdle: finding the regionID info from the non-loaded map.

    namely, I am trying to find the (x,y) position of a designated region, and to use that position to call transfer player and send them to that spot (really any kind of tile data will do, so long as its something i can isolate and use to designate a landing spot for the player)

    and the mapdata I assume keeps it all its tile info in an array(?) called data, which i am unsure how to parse to find the relevant info i need. is this the right place to be looking for this data? and if so how do i check it?
  5. Jetyl said:
    Okay, that gave me the help i needed, and i now can pull up non-loaded mapdata. however I am now hitting my next hurdle: finding the regionID info from the non-loaded map.
    Usually map stuff like region ID is parsed via Game_Map, e.g. (*_objects.js):
    Game_Map#regionId
    JavaScript:
    Game_Map.prototype.width = function() {
        return $dataMap.width;
    };
    
    Game_Map.prototype.height = function() {
        return $dataMap.height;
    };
    
    Game_Map.prototype.isValid = function(x, y) {
        return x >= 0 && x < this.width() && y >= 0 && y < this.height();
    };
    
    Game_Map.prototype.tileId = function(x, y, z) {
        const width = $dataMap.width;
        const height = $dataMap.height;
        return $dataMap.data[(z * height + y) * width + x] || 0;
    };
    
    Game_Map.prototype.regionId = function(x, y) {
        return this.isValid(x, y) ? this.tileId(x, y, 5) : 0;
    };
  6. okay parsing that I am able to get the output i am expecting in my test scenario at least.

    however I am not sure what the "Game_Map.prototype" part is doing. like i find the appropriate region id from taking the "$dataMap.data[(z * height + y) * width + x]" line and plugging in the specific tile info directly (for testing of course), but outside the test case I am going to want to loop thru all (x,y) positions to find the region id, so having a function call for regionID like above would be good, but idk how I am supposed to tie that to the map data i get from the xhr call.

    code for my test function
    JavaScript:
    var testID = 1;
    PluginManager.registerCommand("DreamDungeon", "MoveTest", args => {
        console.log(args.mapId);
        testID = args.regionID;
        var data = LoadDataFile(args.mapId, loadSuccess)
    }); 
    function LoadDataFile (mapId, onload, context) {
    var src = 'Map%1.json'.format(mapId.padZero(3));
        var xhr = new XMLHttpRequest();
        var url = 'data/' + src;
        var result = null;
        xhr.open('GET', url);
        xhr.overrideMimeType('application/json');
        xhr.onload = function() {
            if (xhr.status < 400) {
                result = JSON.parse(xhr.responseText);
                result.id = mapId;
                // On a succesful map load we then call our 'onload' function and pass in the result.
                onload.call(context, result)
            }
        };
        xhr.onerror = function(err) {
            console.log("Failed to load Map Info");
        };
        xhr.send();
    };
    // This function will be called when the data file is loaded
    var loadSuccess = function (data) {
        console.log('Load Success', data);
        var pos = FindRegionID(testID, data);
        $gamePlayer.reserveTransfer(data.id, pos.x, pos.y, 0, 0);
        
    }
    function FindRegionID(id, data) {
        for (let i = 0; i < data.width; i++) 
        {
            for (let j = 0; j < data.height; j++) 
            {
                if(data.regionId(i,j) == id) //data.regionID does not exist
                {
                    console.log('Region ID:', id, "found at (", i, ",", j, ")");
                    //output should be the x,y pos for regionid
                    var position = { x: i, y: j };
                    return position;
                }
            }
        }
    };
  7. Jetyl said:
    i find the appropriate region id from taking the "$dataMap.data[(z * height + y) * width + x]" line and plugging in the specific tile info directly (for testing of course), but outside the test case I am going to want to loop thru all (x,y) positions to find the region id, so having a function call for regionID like above would be good, but idk how I am supposed to tie that to the map data i get from the xhr call.
    Jetyl said:
    JavaScript:
    function FindRegionID(id, data) {
    ...the map data is right there, no? :kaoswt:

    Jetyl said:
    JavaScript:
                if(data.regionId(i,j) == id) //data.regionID does not exist
    Like I said, regionId is a Game_Map method. The map data (e.g. $dataMap) is a generic object with an entirely different structure and purpose. You could define e.g. function regionId(data, x, y) to fetch the appropriate value.

    Jetyl said:
    I am not sure what the "Game_Map.prototype" part is doing.
    JavaScript implements instancing and inheritance using a prototype model, rather than a strict class model. It seems you've jumped in at the deep end, without experience of JS or maybe even OOP? If you want more thorough responses then I suggest you start a new thread in Learning JavaScript~ :kaohi:
  8. caethyril said:
    It seems you've jumped in at the deep end, without experience of JS or maybe even OOP?
    I know about OOP, i've just had most of my experience in C#. this is my first real experience with JS tho yeah. and yeah i kinda am jumping into the deep end, since most of how i learn best is making a thing I wanna make, struggling and slowly improving (plus i chose to make project this in rpg maker to specifically reduce the amount of coding I'd have to do for it. this specific functionality is kinda the exception since its sorta core to my game idea), hence me not really knowing the exact syntax for things, or exact differences between C# and JS.

    but yeah if i have more questions on that end of things i'll go make a thread in learning javascript

    caethyril said:
    ...the map data is right there, no? :kaoswt:
    it is, i was mostly confused by the "Game_Map.prototype", since understanding that might've changed change how i wrote the function to pull the relevant info out of the data.

    either way I now have my test case working in full, so thank you!
  9. Hopefully a quick one:
    I'm using YEP_Equipcore to change normal equip-slots characters have (and to have 6 slots on everyone), this all works fine.
    However, I have two characters that have 2x Accessory slots, and the editor does not support giving them a second item on the game start.
    I have tried the following in my game startup common event:
    Code:
    var actor = $gameActors.actor(6);
    var slot = 5;
    actor.changeEquip(slot, $dataArmors[142]);
    But that doesn't seem to work.

    This character's class has the notetag:
    <Equip Slot: 1,2,12,5,9,9>
    Specifically, that's Weapon, Body, Hat, Charm, Accessory, Accessory, and I'm assuming that the slots are 0/1/2/3/4/5.

    What am I doing wrong here?
  10. Did you give your party the accessories before trying to equip them?
  11. rpgLord69 said:
    Did you give your party the accessories before trying to equip them?
    Goddamn, that simple, huh? LE SIGH.

    The default "Change Equipment" command forces that item to appear in the slot regardless of whether you have it in inventory or not, so I assumed the script call functioned the same way.

    EDIT: Weirdly, that then causes a duplicate of that item to appear in the inventory as well. But fixable by removing -1 after using the script call. Very bizarre though.
  12. Does the base event command do that? I checked the code and doesn't seem like it should. And tested it quickly and it didn't seem to do that.
  13. rpgLord69 said:
    Does the base event command do that? I checked the code and doesn't seem like it should. And tested it quickly and it didn't seem to do that.
    Yep, at least for me. I have, for example, been testing a higher level dungeon quickly by changing levels and items like this on autorun that switches itself off immediately:
    1780494633660.png
    And this immediately occurs in game:
    1780494712813.png
    With the old items appearing in inventory.