0

わかりましたので、フラッシュ ゲーム用に取り組んでいるデバッグ システムがあり、そこに Switch(case) ブロックがあります。

switch (fstring){

case "player.getname":
var pname = _global.heroVars.playerName;
target.feedback.text +=  (ct + pname + "\r\n");
target.inputt.text = "";
break;

case "player.getlevel":
var plevel = _global.heroVars.userLevel;
target.feedback.text += (ct + plevel + "\r\n");
target.inputt.text = "";
break;

default:
target.feedback.text += (ct + "\"" + inp + "\"" + " is not a valid function\r\n");
target.inputt.text = "";
}

私の質問は、「設定」機能になるようにするにはどうすればよいかということです。たとえば、
「player.setlevel NUMBERHERE」または「player.setname STRINGHERE」など。文字列の 2 番目の部分を取り、その番号または文字列を使用して変数を設定しますか?

4

1 に答える 1

0

やり方がわかった。

この文字列「_player.addlevels 2」の例では、var inputFuncとして

var mystring:String = inputFunc; // sets it to a new var to not mess up the original
var sepString:Array = mystring.split(" "); // splits "_player.addlevels" and "2"
var func:String = sepString[0]; // sets this string to "_player.addlevels"
var inputVar:String = sepString[1]; // sets this string to "2" which can be anything and cast into another var type

switch(func){ // takes our variable with the string "_player.addlevels"
    case "_player.addlevels":
        _global.playerLevel += int(inputVar); //since they are using this function we know that they are using and integer and thus cast the string to an int
    break;
}

以前はどうだったのかわかりませんが、自分の問題を解決することになりました。誰かが興味を持っている場合に備えて、答えがあります

于 2012-10-22T12:15:01.157 に答える