Waring Beeps (SOLVED

For questions about using Classic.

Post » Thu Oct 14, 2010 7:39 pm

How do use "every x milliseconds" command after hitting a button?

I want the "every x milliseconds" command to start after I hit a button
B
28
S
8
G
8
Posts: 530
Reputation: 7,154

Post » Thu Oct 14, 2010 9:16 pm

Just make sure a condition is met and run the "every..." event as a sub-event.

+ On left clicked on Sprite
-> System: Set global variable 'warning' to 1

+ Is global variable 'warning' equal to 1
++ Every x milliseconds
-->do whatever is needed after the button was clicked
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Oct 14, 2010 9:45 pm

Thank you
B
28
S
8
G
8
Posts: 530
Reputation: 7,154

Post » Thu Oct 14, 2010 11:18 pm

Need some debug help
http://www.box.net/shared/6ac37tfmk9


The initial 1 min and 3 minute timer works

But I can not change my mind and select a different time once one started. Also after hitting stop I can not restart

Any thoughts?
B
28
S
8
G
8
Posts: 530
Reputation: 7,154

Post » Fri Oct 15, 2010 2:11 am

[quote="Guyon":19uyewgd]Need some debug help
http://www.box.net/shared/6ac37tfmk9


The initial 1 min and 3 minute timer works

But I can not change my mind and select a different time once one started. Also after hitting stop I can not restart

Any thoughts?[/quote:19uyewgd]
Don't mix the code and the behaviour of the xaudio2 object here :)

The basic code is correct. It changes 'TimerCheck' to the correct values. The problem is the way you use xa2. You order it to autoplay, that means it will use the next free channel to play whatever it needs to play, until the end of the soundfile is reached. This is not sufficient for your needs I think.

Instead, use xa2's 'Load file' to bind the soundfile to a specific channel, and use xa2's 'Play' to play the sound. When hitting the stop button you should then also stop the sound.

To reset the sound, just set the channel's position to zero.

You don't want to repeat an action every x milliseconds, you rather want to loop a timespan for a specific amount of time (until you hit stop) beginning with a button being pressed. I would recommend to use Timer and a global 'TimeStamp" for this task. With modulo you will get a loop over the allowed timespan. There's just one thing to pass attention to: Timer is an exact value, whereas your events are executed within a tick that may last for several milliseconds. That's why you can't directly compare to zero but a range. For most event sheets, one TimeDelta-range should be enough. TimeDelta is a fraction of a second, so multiply it by 1000 to get a milliseconds value to compare with. If your project grows and you happen to not hear the sound playing, just raise that value in TimeDelta steps (so the next range to compare with would be TimeDelta * 2000)

btw, you shouldn't raise the volume to 25db, or you will risk the ears of your users. For very quiet sounds setting the master volume to 6 or at maximum 12 db may be ok. On the other hand, there's always the limiter, if you didn't touch it, it will at least prevent distortion. Also, there is no way to restore to 0db right now.

Yeah, sounds more complicated than it is, really. Have a look at your reworked cap:
rwTimer.cap
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Fri Oct 15, 2010 6:52 pm

tulamide,
You approach worked out perfectly, though I am now going back to see exaclly whay it worked. XAudio2 seems to have some rules I did not pick up on, but well woth understanding.

Thank you so much for the fast reply!
B
28
S
8
G
8
Posts: 530
Reputation: 7,154


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 8 guests