pawn-lang / YSI-Includes

Just the YSI include files, none of the extra stuff.
210 stars 107 forks source link

y_inline_timers calling the timer function twice #666

Open zsoolt997 opened 8 months ago

zsoolt997 commented 8 months ago

The print function will be called twice with this code:

#include <open.mp>
#include <YSI_Coding\y_timers>
#include <YSI_Extra\y_inline_timers>

main() {}

public OnGameModeInit()
{
    inline CheckDoubleCall() {

        print("Debug message.");
    }
    Timer_CreateCallback(using inline CheckDoubleCall, 1000, 5 * 1000, 0);

    return true;
}

Console output:

[2024-01-30T20:23:17+0100] [Info] Legacy Network started on port 7777
[2024-01-30T20:23:18+0100] [Info] Debug message.
[2024-01-30T20:23:18+0100] [Info] Debug message.
[2024-01-30T20:23:23+0100] [Info] Debug message.
[2024-01-30T20:23:23+0100] [Info] Debug message.
[2024-01-30T20:23:28+0100] [Info] Debug message.
[2024-01-30T20:23:28+0100] [Info] Debug message.

You can see the print function gets called twice every 5 seconds.

This piece of code will run just fine:

#include <open.mp>
#include <YSI_Coding\y_timers>
#include <YSI_Extra\y_inline_timers>

main() {}

@timer(5 * 1000, .initial = 1000, .repeat = 3) CheckDoubleCall()
{
    print("Debug message.");
}

Console output:

[2024-01-30T20:26:25+0100] [Info] Legacy Network started on port 7777
[2024-01-30T20:26:30+0100] [Info] Debug message.
[2024-01-30T20:26:35+0100] [Info] Debug message.
[2024-01-30T20:26:40+0100] [Info] Debug message.
[2024-01-30T20:26:45+0100] [Info] Debug message.
[2024-01-30T20:26:50+0100] [Info] Debug message.
[2024-01-30T20:26:55+0100] [Info] Debug message.
[2024-01-30T20:27:00+0100] [Info] Debug message.

Fact, the optional parameters doesn't work, because the timer doesn't get called after 1 second and gets called more than 3 times. Two bugs (sorry), if you want I can open another issue..

Y-Less commented 5 months ago

I fixed the first of these, then I looked at the second. I couldn't work out for a while how it was supposed to work, then I realised that isn't supported syntax. I can't remember if that was the plan at some point and I mentioned it somewhere, but it isn't in right now. The syntax there makes this timer a task, so it runs automatically and forever. The .repeat and .initial parameters are ignored. If they were used for a normal timer there's currently only defer and repeat to start a timer, neither of which really make sense with a repeat count. Unifying y_timers and y_inline_timers would be best, I'm just not sure how right now.