Is there a way to fire an action only once in a detect event

Get help using Construct 2

Post » Wed Apr 22, 2015 6:16 am

The title sounds off. Ok, here's what I've got. I'm detecting keyboard input from the INPUT box in the event sheet. So it looks something like this:

On Text Change -> Wait for 1 sec and do my action here...

This isn't what I'm looking for of course as every time I input a key and thus, a text change is detected, it fires accordingly. So if I type up "hello" quickly, it'll run the action 5 times (there are 5 letters).

So I'm looking for a way to detect changes on the text box but only fire my action once given a certain time period where no more changes are detected. So if I type up "hello" quickly, it'll fire the action only 1 time. So in JS, it's something like this:

Code: Select all
var timer;
var interval = 3000;       // Delay in ms before the action will run

$('#inputbox').keyup(function(e) {
    if (timer)
        clearTimeout(timer);

    timer = setTimeout(action, interval);
});

function action() {
   //My actions here
}


Is there something of a rough equivalent to this that anyone knows about?
B
7
S
1
Posts: 42
Reputation: 1,058

Post » Wed Apr 22, 2015 6:36 am

something like this?

Image

you can use textbox instance variable..
Image
B
64
S
23
G
7
Posts: 1,483
Reputation: 10,827

Post » Wed Apr 22, 2015 6:47 am

Ah let me try that. That's a subevent no? And this subevent acts like a nested condition?
B
7
S
1
Posts: 42
Reputation: 1,058

Post » Wed Apr 22, 2015 7:10 am

Hmm it seems the wait is fixed at 1 sec. Is there a way to reset the wait counter (count back from 0) whenever a keypress (within the set timeout) is made?
B
7
S
1
Posts: 42
Reputation: 1,058

Post » Wed Apr 22, 2015 8:20 am

I suppose this'll work. Is there an equivalent of the clearTimeout(timer) part within in Construct 2 though?
B
7
S
1
Posts: 42
Reputation: 1,058

Post » Wed Apr 22, 2015 8:38 am

so.....
if I understood correctly...you want something like this:

only if player stop typing for 1 sec then trigger action........

capx:
http://s000.tinyupload.com/index.php?fi ... 2373144964
Image
B
64
S
23
G
7
Posts: 1,483
Reputation: 10,827

Post » Thu Apr 23, 2015 4:38 am

Yes, something like that! Thanks for the example.
B
7
S
1
Posts: 42
Reputation: 1,058

Post » Thu Apr 23, 2015 8:55 am

You could use the timer behavior: textChangedTimer.capx (r200)
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Thu Apr 23, 2015 8:59 am

Yes, it is much simpler solution :D
Image
B
64
S
23
G
7
Posts: 1,483
Reputation: 10,827


Return to How do I....?

Who is online

Users browsing this forum: jasontoups, OddConfection and 1 guest