0

好的,所以我有一个正在为 Flash 游戏开发的调试系统,并且我有一个 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”等。并取字符串的第二部分并使用所述数字或字符串来设置变量?

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 回答