【发布时间】:2022-01-10 06:00:35
【问题描述】:
晚安,伙计们。
我是编程新手,不到 2 个月,所以我不太明白如何进行这项工作。这正是我想要做的: 我有一个我正在尝试制作的游戏,它需要在符合条件“活着”并且“能够使用奖品”的现有单位之间进行抽奖。为此,有人告诉我,我需要为可以接收它的单元包含一个带有单元 ID 的数组,然后通过“活着”过滤它们以供随机生成器进行选择。问题是,我不知道如何使这项工作。我试过这段代码,但它不起作用。任何人都知道我为什么或如何这样做?
var rafflearray = []; // the array containing the units
if (root.getExternalData().isUnitRegistered() = true) {var character = root.getCurrentSession().getPlayerList().getData()}; // establish the character as a variable
if (var character.getAliveStatus = true ) {rafflearray.push(character)}; // checks his alive status and send him to the array
var chosen = rafflearray [Math.random()*chosenarray.lenght]; // to choose amongst them
chosen.addItem()
提前感谢您的关注!
【问题讨论】:
-
Math.floor(Math.random() * selectedArray.length) - 试试这个
标签: javascript arrays filter