Variable called by function for screen resolution

Discussion in 'Javascript/Plugin Support' started by spolen, Jan 27, 2017.

  1. spolen

    spolen Villager Member

    Messages:
    12
    Likes Received:
    1
    First Language:
    English
    I am having an issue with a script I'm working on, I am trying to call the x and y variables to set the screen resolution, and now my brain is hurting after a little while of editing and re editing, and searching online for any way to pull this off.


    I am using Yanflys Core Engine with a resolution set at 1360x768, and I suspect that may be part of the issue, but I am unsure of how to do this with that script.


    //Sets variables and calls those variables to functions in order to select screen resolution
    var x = 1024;
    var y = 768;
    //
    (function() {Graphics.width(x);})();
    (function() {Graphics.height(y);})();
    (function() {Graphics.boxWidth(x);})();
    (function() {Graphics.boxHeight(y);})();


    I am able to change resolution in game by adding the following to an event

    Code:
    Graphics.width = 1024;
    Graphics.height = 768;
    Graphics.boxWidth = 1024;
    Graphics.boxHeight = 768;
     
    Last edited by a moderator: Jan 27, 2017
    #1
  2. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,969
    Location:
    Philippines
    First Language:
    Tagalog


    I think it should be 


    (function() {Graphics.width = x;})();


    and so on


    Though I don't know if those functions will be called. Basically the .width etc functions return the width object so you need to use operators to set them instead of feeding values as parameters to them.


    or you might not even encapsulate them in function and just write it directly as


    Graphics.width = x;


    and so on


    Now whether or not Yanfly's plugin intercepts your code depends on which ever code is ran first. If yanfly's get ran first, then it will be yours to remain, but if yours get ran first then yanfly's will be the effect to remain. If that code of yours isn't part of any other code block, it will probably run during setup which means it will also probably run before Yanfly's so yanfly's will overwrite the changes that it will do. If I remember right, Yanfly's plugin changes it during the loading of the very first scene which is Scene_Title. So for your code to actual have a lasting effect, you need to make sure that it is ran after Yanfly's, not before.


    This is also why it worked when you did it via events, since the events are ran after Yanfly's script is already done. Aside from the fact that your events used = instead of trying to supply the values as parameters


    Out of curiosity, why are you trying to do it outside of Yanfly's plugin if you have it installed anyway?
     
    Last edited by a moderator: Jan 27, 2017
    #2
  3. spolen

    spolen Villager Member

    Messages:
    12
    Likes Received:
    1
    First Language:
    English
    thanks for the info, I am trying to so it in a separate plugin because as far as I can tell there's no way of using yanflys plugin to allow the player to change the resolution, or have the game figure out the native resolution on it's own, I could've overlooked something in it though as I am not knowledgeable about javascript, using RPG Maker MV is the first real experience I've had with it.
     
    #3
  4. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,969
    Location:
    Philippines
    First Language:
    Tagalog
    Then I suggest just editing Yanfly's plugin for the initial setup that you need... That way you only have one plugin modifying the game screen size rather than 2 or more.


    Or well, just overwrite the same method that Yanfly uses to modify the size and put your plugin below his so that your plugin will run but Yanfly's own size modification will not. 


    Anyway, I think the only problems here are:


    1) You used .width(x); rather than .width = x;


    2) Your code is ran during setup (if it runs at all) which might mean it will probably run before Yanfly's resulting to Yanfly's plugin overriding whatever changes you did


    So once you solve those, it will most probably work.
     
    Last edited by a moderator: Jan 27, 2017
    #4
    spolen likes this.
  5. spolen

    spolen Villager Member

    Messages:
    12
    Likes Received:
    1
    First Language:
    English
    well it seems I got it working for now,I noticed a difference in yanfly core engine, I ended up having to use the following, and load the script right after yanfly core engine


    SceneManager._screenWidth = x;
    SceneManager._screenHeight = y;
    SceneManager._boxWidth = x;
    SceneManager._boxHeight = y;


    so the script as of now looks like this

    Code:
    var x = 1024;
    var y = 768;
    
    (function(){Graphics._switchFullScreen()
    			SceneManager._screenWidth = x;
    			SceneManager._screenHeight = y;
    			SceneManager._boxWidth = x;
    			SceneManager._boxHeight = y;
    
    
    })();
     
    #5

Share This Page