Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

y_inline_timers calling the timer function twice #666

Open
zsoolt997 opened this issue Jan 30, 2024 · 1 comment
Open

y_inline_timers calling the timer function twice #666

zsoolt997 opened this issue Jan 30, 2024 · 1 comment

Comments

@zsoolt997
Copy link
Contributor

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
Copy link
Member

Y-Less commented Apr 24, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants