# Do an action every tick for X seconds?

Get help using Construct 2

### » Wed Feb 13, 2013 11:20 am

This is probably plain as day, but I am missing it.

I want my PC to walk away from the wrong direction, so I start ignoring input and every tick simulate pressing left.

How do I do this action for only 1 second?

So "every tick" simulate control left "for x Seconds".

If someone could point me in the right direction I would be greatful. But please don't tell me exactly how to do it, I learn better that way, just need a steer in the right direction.
B
9
S
3
Posts: 151
Reputation: 1,749

### » Wed Feb 13, 2013 11:26 am

The problem is right there in your logic: you can't do something for 1 second every tick. Every tick is usually every 1/60th of a second.

If you want to do something for X seconds, you need to have a more specific condition, like "on keypress", "on key released" or "on collision"
B
57
S
15
G
11
Posts: 912
Reputation: 12,646

### » Wed Feb 13, 2013 11:39 am

[QUOTE=Awakening] This is probably plain as day, but I am missing it.

I want my PC to walk away from the wrong direction, so I start ignoring input and every tick simulate pressing left.

How do I do this action for only 1 second?

So "every tick" simulate control left "for x Seconds".

If someone could point me in the right direction I would be greatful. But please don't tell me exactly how to do it, I learn better that way, just need a steer in the right direction.[/QUOTE]

This could work:

Variable DisableControls = 1

Every 1 seconds
..DisableControls > 0
... Subtract 1 from DisableControls
... Set controls disabled

..Else
...Set controls enabled

Then you'd have another event where you define your walk left action.

// walk scene starts
.. DisableControls = 1
B
24
S
9
G
7
Posts: 756
Reputation: 7,322

### » Wed Feb 13, 2013 12:51 pm

B
52
S
16
G
9
Posts: 1,098
Reputation: 11,267

### » Wed Feb 13, 2013 2:29 pm

[QUOTE=GeometriX] The problem is right there in your logic: you can't do something for 1 second every tick. Every tick is usually every 1/60th of a second.

If you want to do something for X seconds, you need to have a more specific condition, like "on keypress", "on key released" or "on collision"[/QUOTE]

I think you misunderstand me. If I want to have an AI move left, it has to be "simulating left" every tick to move smoothly. But how do I then get the AI/or a PC whose control is taken away from the player to stop after going left for 3 seconds?

So to be plain, I want to make something simulate pressing down left for 3 seconds. How do I do this so it moves left for 3 seconds then stops?Awakening2013-02-13 14:30:35
B
9
S
3
Posts: 151
Reputation: 1,749

### » Wed Feb 13, 2013 5:29 pm

B
55
S
29
G
19
Posts: 1,520
Reputation: 25,780

### » Wed Feb 13, 2013 5:50 pm

So there isn't just an expression instead of "every x seconds" something like"

"for 3 seconds" do this action...
B
9
S
3
Posts: 151
Reputation: 1,749

### » Wed Feb 13, 2013 6:00 pm

[QUOTE=Awakening] So there isn't just an expression instead of "every x seconds" something like"

"for 3 seconds" do this action...[/QUOTE]

Nope, you could do it like I suggested, with timer variable.
B
24
S
9
G
7
Posts: 756
Reputation: 7,322

### » Wed Feb 13, 2013 6:06 pm

[QUOTE=vee41] [QUOTE=Awakening] So there isn't just an expression instead of "every x seconds" something like"

"for 3 seconds" do this action...[/QUOTE]

Nope, you could do it like I suggested, with timer variable.[/QUOTE]

Yeah thanks! I might do that! Seemed pretty straight forward. I just assumed there was an expression or something hehe.

However in this case, I just put a "when collide with object stop moving" type dealie, because I wasn't running a fully featured group of AI events, but more of a scripted event.

Thanks though! I appreciate everyones input.

B
9
S
3
Posts: 151
Reputation: 1,749