Custom Menu Scene freezing

Discussion in 'Learning Javascript' started by Jimminybob, Apr 12, 2018.

  1. Jimminybob

    Jimminybob Villager Member

    Messages:
    24
    Likes Received:
    7
    First Language:
    English
    Primarily Uses:
    RMMV
    Hi all,

    I've got a custom scene/window in my menu that i'm using to display an image of the game map to the user. I've noticed though that when I access this item on the menu the whole thing seems to freeze.

    I've checked the console and there are no errors, and making it log it's progress shows that it does indeed go through the complete code for this menu option, but nothing shows and I am then unable to do anything. It's almost like the game has crashed or the code is getting stuck somewhere, but i can't see where.

    Below is the section of code related to this, if anyone can help that would be very much appreciated.

    Code:
    function Scene_MapBase () {
            this.initialize.apply(this, arguments);
        };
    
        Scene_MapBase.prototype = Object.create(Scene_MenuBase.prototype);
        Scene_MapBase.prototype.constructor = Scene_MapBase;
    
        Scene_MapBase.prototype.initialize = function(){
            Scene_MenuBase.prototype.initialize.call(this);
        };
    
        Scene_MapBase.prototype.create = function() {
            Scene_MenuBase.prototype.create.call(this);
        };
    
    
        function Scene_Map() {
            this.initialize.apply(this, arguments);
        }
    
        Scene_Map.prototype = Object.create(Scene_MapBase.prototype);
        Scene_Map.prototype.constructor = Scene_Map;
    
        Scene_Map.prototype.initialize = function() {
            Scene_MapBase.prototype.initialize.call(this);
        };
    
        Scene_Map.prototype.create = function() {
            Scene_MapBase.prototype.create.call(this);
            this.createMapWindow();
        };
    
        Scene_Map.prototype.createMapWindow = function() {
            this._mapWindow = new Window_DrawMap();
        };
    
    
        function Window_DrawMap () {
            this.initialize.apply(this, arguments);
        };
    
        Window_DrawMap.prototype = Object.create(Window_Base.prototype);
        Window_DrawMap.prototype.constructor = Window_DrawMap;
    
        Window_DrawMap.prototype.initialize = function(x, y){
            var x = 420;
            var y = 20;
            var width = 350;
            var height = 590;
            Window_Base.prototype.initialize.call(this, x, y, width, height);
            this.refresh();
        };
    
        Window_DrawMap.prototype.refresh = function(){
            this.drawFloorplan();
        }
    
        Window_DrawMap.prototype.drawFloorplan = function(){
            var bitmap = ImageManager.loadPicture("Floorplan");   
            this.contents.blt(bitmap, 0, 0, bitmap._canvas.width, bitmap._canvas.height, 0, 0);
        };
    Many thanks
     
    #1
  2. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,660
    Likes Received:
    9,208
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    I don't understand two things:
    1. What handles the default maps? Did you rename the default one?
    2. Why did you have to create Scene_MapBase when all it does is call Scene_MenuBase functions without any edits?

    Other than that, the mistake is here:
    Code:
    Scene_Map.prototype.createMapWindow = function() {
            this._mapWindow = new Window_DrawMap();
        };
    You're missing one line:
    Code:
    this.addWindow(this._mapWindow);
    And you will also need some window that is capable of using handlers so that you can return from the Scene.
     
    #2
  3. Jimminybob

    Jimminybob Villager Member

    Messages:
    24
    Likes Received:
    7
    First Language:
    English
    Primarily Uses:
    RMMV
    Hi,

    I couldn't see any default function to handle showing maps, so I wasn't aware that there was one. If there is one though that i've missed then i'll happily look into using that.

    I added that in because i'm not very knowledgeable on getting custom menu code to work yet, so I added that in thinking that I needed it (I coped the item structure up to a point) but if it's not needed then I'll get rid.

    Thanks
     
    #3
  4. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,660
    Likes Received:
    9,208
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    Scene_Map is responsible for normal gameplay. If I do a custom menu scene, I add Menu before the scene. So for map I'd do Scene_MenuMap instead.
    As for MenuBase and stuff, that has more to do with object oriented programming than with MV structure. I'd recommend you take a look at that.
     
    #4
  5. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,456
    Likes Received:
    930
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    @Poryg There might be a misunderstanding here. I believe @Jimminybob is creating a scene to display a map of the world/dungeon - like one printed on paper (or created by a cartographer). I'm guessing the main menu options are like:
    -Items
    -Skills
    -Status
    -Map
    -Save
    -Exit
    (etc.)

    Apologies if I misinterpreted, or if you already had that understanding.
     
    #5
  6. Jimminybob

    Jimminybob Villager Member

    Messages:
    24
    Likes Received:
    7
    First Language:
    English
    Primarily Uses:
    RMMV
    @Aloe Guvner That's correct yeah, that's how my menu is. Sorry for the confusion in my first post.

    But yeah effectively I have got an image that i've drawn of the game map that I want the user to be able to see when they go on the Map option in the menu. After your post @Poryg I've been able to get it to show the image but now I've still got the issue where I can't do anything afterwards.

    I assume i've got to make it go back to the window where the menu options are so that the user can choose from them again, as there's nothing to actually select, or even a cursor, on my map window.
     
    #6
  7. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,660
    Likes Received:
    9,208
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    That is what I have said :Dยจ
    Make a simple command window with command Back.
     
    #7
  8. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,456
    Likes Received:
    930
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    You could even make the command window invisible so the player isn't aware of it, but it still works.

    Another way is to hook into the "update" method of the scene, something like this:
    Code:
    Scene_MenuMap.prototype.update = function() {
       if (Input.isTriggered("escape") {   
          SoundManager.playCancel()
          this.popScene();
       }
       if (Input.isTriggered("ok") {
          SoundManager.playCancel()
          this.popScene();
       }
       Scene_MenuBase.prototype.update.call(this);
    };
    
    And yeah, like Poryg said if it is supposed to be a menu, you don't want to overwrite Scene_Map. Otherwise your characters can't walk around.
     
    #8

Share This Page