2018-12-11 03:58:12

This is a basic question, but it needs to be answered please. I am using bgt by the way.
if(timer.elapsed==13000)
No matter what I want to do, pause the timer, play a sound, or anything else, the timer just ignores it and keeps running and nothing happens. How can I fix this to make the timer pause or play a sound at a certain point? What line do I write instead of that one?
Thanks. Basic things like this piss me off in coding. I suck at coding, but that's only half the problem. I blame the other half on bgt being a dumb ass. Or maybe I'm the dumb ass. Whatever the case, I'd like to eliminate this problem, and I don't mean to act rude and beg for help. Just so many basic things like that that prevent me from going farther.

2018-12-11 04:26:48

I don't know if the timer has drift or not. Most timers don't, but if BGT's does, then you'll need to change your operator to >= instead of ==. Also, did you actually start the timer (if it needs starting), and did you restart the timer to reset its time interval to 0?

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2018-12-11 04:35:22 (edited by Zarvox 2018-12-11 04:38:34)

yes, the timer is already running. Also, >= does not work.
I tried == several times, and it didn't pause, then I tried it a few minutes later and apparently it worked.
What I am mainly interested in is playing a sound. I can't use the p.play_stationary to do this, but dlgplayer and sound.play() both work. However, the dlgplay and sound.play() functions only played the sound 2 out of 3 times, in 3 seconds. And, the dlgplay function pauses other sounds while that sound plays, and that's not good. I tried removing that code but it doesn't want to go away. The p.play_stationary plays a sound again even if it is not finished playing the first one, but these toher 2 wait for the sound to finish, can I somehow eliminate that?

2018-12-11 04:50:24

Something is clearly wrong. If I have it do the same thing like speak one second, then play a sound the next, it randomly chooses what seconds to do and what seconds to ignore. I have tested this with  playing sounds, and speaking. So what's going on?

2018-12-11 06:31:43 (edited by Stiboly 2018-12-11 06:32:46)

timer test;
if(test.elapsed>=13000)
{
test.restart();
p.play_stationary("test.ogg",false);
}

Don't care.

2018-12-11 06:35:34

I would like the timer to continue

2018-12-11 08:12:06

Hi zarvox, i don't advise you to use the dlg player for this. it may be slow, because it loads the sound into memory before it plays. that is why you should not use the dlg player for this, rather use the sound pool.
it is quite easy to use.
sound_pool p;
timer test;
void main()
{
if(test.elapsed>=13000)
{
test.restart();
p.play_stationary("sound.ogg",false);
}
}
and the timer will continue, don't worry.

best regards
never give up on what ever you are doing.

2018-12-11 10:57:33

hi.
If you would like the timer to continue, just remove the restart line.
Just do note, that if you remove the restart line, I'll only play 1 time.
Also note, that 13000 is equal to 13 seconds and you need to use >= in order for it to work (look in the manual for an explenation).
timer test;
if(test.elapsed>=13000)
{
p.play_stationary("test.ogg",false);
}

If you like what I do, Feel free to check me out on GitHub, or follow me on Twitter

2018-12-14 09:02:24

problem with not resetting the timer is that the sound will continuously trigger. I sometimes use a timer based on 1000 MS and so every 1000 MS the timer resets and increments a value by 1. I'm not sure if this will exactly run. I haven't touched VGT in several months, but this sort of illustrates what I'm talking about. I even indented it too. Because indentation is life.


void main()
{
    timer tmr;
    int clock;
    if (tmr.elapsed >= 1000)
        {
        tmr.restart();
        clock ++;
        if (clock == 13)
            {
            #play a sound or something
            }
        if (clock == 30)
            {
            exit();
            }
}
}

Much less active on this forum than in the past.

Check out my live streams: http://lerven.me
follow me on Twitter: http://twitter.com/liamerven

2018-12-14 09:10:53

Liam has the right solution. The BGT manual makes timers sound like a general solution to all timing-related problems, but it really should be only a part of the solution. There's no telling what a computer will do to throw off timing (especially when multiplayer is involved), especially as Windows becomes increasingly autonomous.
So what you really want is to use the timer to find intervals. Using the timer just to track when one second has passed, then resetting it and incrementing a second-counter, is far more reliable. It also prevents dropping seconds, even if something causes the program to lag.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2018-12-14 09:19:31

Yes. Never use a timer to try to time out a large portion of time. I like the 1000 MS approach as you can keep track of how long your game has been running and use that data against a higher number to find remaining time.
The only time this is ever a problem if your program does something that causes it to block for more than a second, but then you have pause and resume to handle this.

Much less active on this forum than in the past.

Check out my live streams: http://lerven.me
follow me on Twitter: http://twitter.com/liamerven

2018-12-14 10:25:55

If the language your using provides it, a simple call to C's time()*1000 would also be sufficient. However, that has its drawbacks, such as the time being moved back several hours, causing nasty surprises. A good idea is to use a monotonic clock. A monotonic clock is a clock that always moves forward and never backwards. It can't be altered or changed. A monotonic clock works by taking an initial value (such as the time your system booted) and uses that as its "epoch". C has its clock_gettime() function in POSIX and GEtTickCount64()/QueryPerformanceCounter() for win32, C++ has std::chrono::steady_clock, Python has time.monotonic(), C# provides System.Threading.Timer, and so on.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2018-12-14 16:17:44 (edited by Zarvox 2018-12-14 16:18:38)

Thanks Liam for a new approach. I never thought of it that way. I should take a course on how to think like a coder lol

2018-12-15 08:58:08

It's not so much how to think like a coder, but I try to think of ways that will minimize errors and offer extra control. Having a timer that counts seconds up or down is pretty sweet on multiple levels.

Much less active on this forum than in the past.

Check out my live streams: http://lerven.me
follow me on Twitter: http://twitter.com/liamerven