timer is not work

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By quangtran

I draw line2d connect to two sprite and I want after short time about 3 second call another funtion will hide two sprite and remove line2d but the timer is not work

public override void _Input(InputEvent @event)
    // Mouse in viewport coordinates.
    if (@event is InputEventMouseButton eventMouseButton)
        int x = (int)eventMouseButton.Position.x;
        int y = (int)eventMouseButton.Position.y;
        if (eventMouseButton.ButtonIndex == 1)
            this.square = u.find_quare(x, y);
            string square_name = this.get_square_name(this.square);
            Square sq = new Square();
            this.array_square_name = sq.save_square_name(this.array_square_name, this.square, square_name);
            bool rs = sq.match(array_square_name);
            if (rs) {
                string[,] b = this.init_board();
                this.sprite1_pos = this.get_sprite_pos(array_square_name[0,0]);
                this.sprite2_pos = this.get_sprite_pos(array_square_name[1,0]);
                this.result = true;
                var t = (Timer)GetNode("timer_clear_line");
                t.WaitTime = 3;
:bust_in_silhouette: Reply From: gioele

Timer does not work that way, it is not a pause in execution.
So you start the timer and it instantly complete execution removing square and line.

Either you use yield to stop execution, putting a line like this before the hide square and line call:

yield(your_timer, "timeout")

Or you connect the timer timeout signal to a custom call back and move there your hide function call.

thank you for your comment it’s userful for me, more about timer also have below link
enter link description here

quangtran | 2020-08-31 14:52