Delayed method call

Is there a way to call methods with a delay? I am creating a timetask right now. I can follow and call with match loop ticking. But that didn’t make me very happy. Because it may also be needed in a non-matchmaking scenario. (TypeScript, Nakama 3.9)

@Faircyan Sounds like you’re trying to implement a background task pattern. We don’t usually recommend this but there are ways to achieve it, yes.

Can you explain what you’re trying to do exactly? Perhaps there’s a better way to do what you want in Nakama.

Hello @zyro
In my scenario, when a new person joins the match, after a while, I want to send some information of the previous users (icon, design, etc.) to the new participants. (Authoritative multiplayer).

Should I send these information with player joined broadcast message?
Can new players listen to this broadcast message?

Thanks.

looks like here is solution for your case Large state data sync issue - #3 by zyro

You could broadcast messages in your match join, or in yout match loop after a number of tick rates, controlling it by using the match state (send this message after tick #X).

1 Like

Thanks. @zyro, @formatCvt and @ftkg.
I understand your concerns, but sometimes we really need it. Example: Let’s consider a scenario where we want to change the themes of the matches to be created every hour. For each newly created match, is it better to calculate and decide on which theme this match will be, or is it better to schedule a method that will run once an hour and make it work? I think it’s the second. What is your suggestion?

To me it seems natural to decide the match type/theme at its creation, as that way you simplify your system by removing an extra layer of dependency (the scheduled worker), and make your code easier to understand. I would just abstract it away in a function and call it at match creation, specially if it is simple logic like hour checks.

1 Like

I am on the same boat. Where I need to add some delay between each action. When the game starts server sends sequence of actions to players such as
Initialize players
Create deck
Distribute cards to each player sequentially with delay (have to show card distribution animation)
Set Turn
Add delay between turns
For all these I need a nakama supported delay system.
These methods are in instanced class objects and cannot access match ticks directly.
I am aware that nakama does not encourage adding delayed called dues the way nakama works, I am looking for solutions for such cases.