Variables 在动作脚本中选择随机变量

Variables 在动作脚本中选择随机变量,variables,actionscript,random,Variables,Actionscript,Random,可以从动作脚本中的变量中随机选择吗 我试过使用或- question.text=question1 | | question.text=question2 提前感谢您的帮助。如果需要随机变量,请使用数组: var x:int = 5; var y:int = 1; var z:int = "string"; var w:int = "bla"; var randomSelector:Array = [x, y, z, w]; var random:* = randomSelector[Math

可以从动作脚本中的变量中随机选择吗

我试过使用或-

question.text=question1 | | question.text=question2


提前感谢您的帮助。

如果需要随机变量,请使用数组:

var x:int = 5;
var y:int = 1;
var z:int = "string";
var w:int = "bla";

var randomSelector:Array = [x, y, z, w];
var random:* = randomSelector[Math.floor(randomSelector.length * Math.random())];

// random is now a random variable from either x, y, z, or w

尝试将选项放入数组,然后从该数组中随机选择索引

var options:Array = ["Hello", "World", "I'm", "alive"];
var randomlySelectedOption:String = options[Math.floor(options.length * Math.random())]