ページ 11

【解決】this.character(-1)でエラーになる

Posted: 2017年8月28日(月) 18:40
by おのき
初めての書き込みです。
ツクールMVを始めてから3日目です。
プログラミングのブランクは5年あり,JavaScriptでの開発はほとんど未経験に近いです。
この度,10年前から開発予定だった新ローグライクを完成させるべく再開しました。
よろしくお願いします。
早速ですが,症状は以下の通りです。

コード: 全て選択

(function() {
  'use strict';//厳格モード

  Game_Player.prototype.moveByInput = function() {
    if (!this.isMoving() && this.canMove()) {
      var player = this.character(-1);//←エラー
      var direction = this.getInputDirection();
      if (direction > 0) {
        $gameTemp.clearDestination();
      }
      else if ($gameTemp.isDestinationValid()) {
        var x = $gameTemp.destinationX();
        var y = $gameTemp.destinationY();
        direction = this.findDirectionTo(x, y);
      }
      if (direction > 0) {
        this.executeMove(direction);
      }
    }
  };
  /*
    TypeError: undefined is not a function
    at Game_Player.moveByInput (***.js:54)
    at Game_Player.update (rpg_objects.js:7668)
    at Scene_Map.updateMain (rpg_scenes.js:609)
    at Scene_Map.updateMainMultiply (rpg_scenes.js:600)
    at Scene_Map.update (rpg_scenes.js:589)
    at Function.SceneManager.updateScene (rpg_managers.js:2024)
    at Function.SceneManager.updateMain (rpg_managers.js:1983)
    at Function.SceneManager.update (rpg_managers.js:1907)
  */
})();

Re: this.character(-1)でエラーになる

Posted: 2017年8月28日(月) 18:46
by まっつUP
おのき様
お世話になります。

Game_Playerやその親クラスに//←エラーとある行の
関数が定義されていないためエラーが起こります。

Re: this.character(-1)でエラーになる

Posted: 2017年8月28日(月) 19:00
by しぐれん
this.character()はGame_Interpreterクラスのメソッドです。
イベントコマンド「スクリプト」は暗黙にinterpreterをthisと設定しています。
プレイヤーを取得したい場合、$gamePlayerを取得してください。

Re: this.character(-1)でエラーになる

Posted: 2017年8月28日(月) 19:03
by おのき
ご返信ありがとうございます。
私は今夜出勤なので,この件は明日確認したいと思います。

Re: this.character(-1)でエラーになる

Posted: 2017年8月29日(火) 12:40
by おのき
確認したところによると,rpg_managers.jsのDataManagerにまとまっていました。
イベントコマンド「スクリプト」は別物なんですね。
とくに考えずwikiのリファレンスに飛びついてしまいました。
お恥ずかしい。
まあそれでもハマっていたことは事実なので,とても助かりました。
素早い対応に感謝します。
ありがとうございました。

コード: 全て選択

var $dataActors       = null;
var $dataClasses      = null;
var $dataSkills       = null;
var $dataItems        = null;
var $dataWeapons      = null;
var $dataArmors       = null;
var $dataEnemies      = null;
var $dataTroops       = null;
var $dataStates       = null;
var $dataAnimations   = null;
var $dataTilesets     = null;
var $dataCommonEvents = null;
var $dataSystem       = null;
var $dataMapInfos     = null;
var $dataMap          = null;
var $gameTemp         = null;
var $gameSystem       = null;
var $gameScreen       = null;
var $gameTimer        = null;
var $gameMessage      = null;
var $gameSwitches     = null;
var $gameVariables    = null;
var $gameSelfSwitches = null;
var $gameActors       = null;
var $gameParty        = null;
var $gameTroop        = null;
var $gameMap          = null;
var $gamePlayer       = null;
var $testEvent        = null;