Google脚本-功能延迟

时间:2019-04-26 03:22:23

标签: google-apps-script

我正在Google表格的序列编辑器中运行此代码。 在修改电子表格后,我需要脚本运行几秒钟。 它可以工作,但延迟功能不起作用。 我的错误是什么?谢谢!!!

class Card {
    constructor(name, image, health, ammo) {
        this.name = name
        this.image = image
        this.health = health
        this.ammo = ammo
    }
}

class Dealer {
    constructor() {
        this.cards = {};
        this.cards.ammo = { specs: ['ammunition', null, 1, null], amount: 4 };
        this.cards.beer = { specs: ['beer', null, 1, null], amount: 4 };
        this.cards.cigar = { specs: ['cigar', null, 1, null], amount: 2 };
        this.cards.enemigo = { specs: ['enemigo', null, -1, null], amount: 2 };
        this.cards.bandito = { specs: ['bandito', null, null, -1], amount: 2 };
        this.cards.snake = { specs: ['snake', null, -1, null], amount: 2 };
        this.cards.scorpion = { specs: ['scorpion', null, -1, null], amount: 2 };
    }

    deal() {
        const outputCards = [];

        Object.keys(this.cards).forEach(d => {
            for (let i = 0; i < this.cards[d].amount; i++) {
                let c = new Card(...this.cards[d].specs);
                outputCards.push(c);
            }
        });

        return outputCards
    }
}

console.log(new Dealer().deal());

1 个答案:

答案 0 :(得分:0)

不确定延迟,但是您可以尝试使用触发器。可以将其设置为在电子表格更新后执行操作。

链接:https://developers.google.com/apps-script/guides/triggers/

链接:https://courses.benlcollins.com/courses/apps-script-blastoff/lectures/8427243(此处有一个示例)