Unknown Scene Error with Variables

Discussion in 'Learning Javascript' started by Milena, Nov 20, 2015.

    Tags:
  1. Milena

    Milena The woman of many questions Veteran

    Messages:
    1,282
    Likes Received:
    106
    Location:
    Ireland
    First Language:
    Irish
    Primarily Uses:
    N/A
    I have made a simple variable like this:

    var milenaSystem = Game_System.prototype.initialize;Game_System.prototype._numbervalue;Game_System.prototype.initialize = function() { milenaSystem.call(this); this._numbervalue = 3;}then made a new variable check at scene map:

    Scene_Map.prototype.update = function() { this.updateDestination(); this.updateMainMultiply(); if (this.isSceneChangeOk()) { this.updateScene(); } else if (SceneManager.isNextScene(Scene_Battle)) { this.updateEncounterEffect(); } this.updateWaitCount(); Scene_Base.prototype.update.call(this); if ($gameSystem._numbervalue === 0) { SceneManager.goto(Scene_Gameover); }};When I decrease the variable _numbervalue until it reaches zero, it should go to Scene_Gameover but it just stays there and the game just stops, the sound is still playing, its just that the scene doesn't go to the scene I want. Anything went wrong?
     
    #1
  2. Zalerinian

    Zalerinian Jack of all Errors Veteran

    Messages:
    4,695
    Likes Received:
    921
    Location:
    The Internet.
    First Language:
    English
    Primarily Uses:
    N/A
    Are there any errors...? What you've given us is not enough to debug the problem. We can't see how the number is changed.
     
    Also, why have this
     

    Game_System.prototype._numbervalue;when you already assign it a value in the initialize function? This is redundant, and therefore not needed.
     
    Also, please give meaningful names to your variables. It will make your life, as well as that of anyone who helps you, easier. After looking at it, it seems clear enough that the purpose of the variable is a life counter, but it'd be better to explicitly state that as it's name. 
     
    could you please better explain this?

     
    #2
  3. Milena

    Milena The woman of many questions Veteran

    Messages:
    1,282
    Likes Received:
    106
    Location:
    Ireland
    First Language:
    Irish
    Primarily Uses:
    N/A
    this is the whole plugin:

    var milenaSystem = Game_System.prototype.initialize;Game_System.prototype.initialize = function() { milenaSystem.call(this); this._numbervalue = 3;}Scene_Map.prototype.update = function() { this.updateDestination(); this.updateMainMultiply(); if (this.isSceneChangeOk()) { this.updateScene(); } else if (SceneManager.isNextScene(Scene_Battle)) { this.updateEncounterEffect(); } this.updateWaitCount(); Scene_Base.prototype.update.call(this); if ($gameSystem._numbervalue === 0) { SceneManager.goto(Scene_Gameover); }};To make the $gameSystem._numbervalue changed, what I do is do this on a script call:

    [​IMG]

    Yes, its a life meter. I'll do that the next time :)

    What I wanted was for the scene to check the value of the life meter everytime, and since it is 3 at the beginning and when I change it, the game just stops working. The music is still playing and when I put a console.log or print something, the developer console plays it. I know that the game is still running, but my controls, are not. 
     
    Last edited by a moderator: Nov 20, 2015
    #3
  4. Zalerinian

    Zalerinian Jack of all Errors Veteran

    Messages:
    4,695
    Likes Received:
    921
    Location:
    The Internet.
    First Language:
    English
    Primarily Uses:
    N/A
    Is the event autorun or anything? That would continually run and prevent any input, though I suppose it wouldn't prevent the scene from changing. After the controls freeze, open the console and verify that the value of the variable is indeed 0.
     
    #4
  5. Milena

    Milena The woman of many questions Veteran

    Messages:
    1,282
    Likes Received:
    106
    Location:
    Ireland
    First Language:
    Irish
    Primarily Uses:
    N/A
    The event is an Action Button. This goes the same when I use Game_Variables instead of a new variable from Game_System. At first, this check is happening on Spriteset_Map, but it just does the same. I tried to print it in the console and the value says it is indeed 0. But this is where my problem lies. If it is 0, shouldn't it transport me to the Game Over scene?
     
    #5
  6. Galv

    Galv Veteran Veteran

    Messages:
    1,171
    Likes Received:
    1,099
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    N/A
    Seems to only happen when you do it via an event. Testing it by other means using your code worked.

    Another option is to make the check when the game already checks for gameover, such as:

    Code:
    (function() {	var milenaSystem = Game_System.prototype.initialize;	Game_System.prototype.initialize = function() {		milenaSystem.call(this);		this._numbervalue = 3;	}		var milenaPartyAlldead = Game_Party.prototype.isAllDead;	Game_Party.prototype.isAllDead = function() {		if ($gameSystem._numbervalue === 0) return true;		return milenaPartyAlldead.call(this);	};})();
     
    #6
    Milena likes this.
  7. Milena

    Milena The woman of many questions Veteran

    Messages:
    1,282
    Likes Received:
    106
    Location:
    Ireland
    First Language:
    Irish
    Primarily Uses:
    N/A
    This works, thanks! But the way I did it sounds weird though, I thought an easy way of checking like that would work. I suppose there was something wrong from doing it via the update scene...
     
    #7

Share This Page