Server/Client Timers

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

SoSilencer

Harry Goz (1932 - 2003)
Nov 27, 2000
834
0
0
42
unrealdev.net
I know what I need to do, but I'm not quite sure how to do it. I'll try to explain as best I can.

.5 second timer
{
do code only on server/host of game
replicate/update variables to clients
}

.1 second timer
{
do this code on all machines, using variables from server
}

That is it really. It's for my rockets. Every half second the server calculates the changes and tells the clients "fly here". Every .1 seconds the rockets figure out by themselves how to fly there (which should be the same on all clients since they are all using the same variables in the same calculations). I can't quite figure out how to tell the code that "this should be done every half second and only on the server" and "this should be done every tenth of a second on all machines". Anyone know how to do that?
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
Use an int variable as a counter:
Code:
class ... extends ...;
...
var int Counter;
...

[u]simulated[/u] function PostBeginPlay()
{
  ...
  SetTimer(0.1, True);
  ...
}

[u]simulated[/u] function Timer()
{
  if ( Counter % 5 == 0 && Role == ROLE_Authority )
    DoServerStuff();
  
  DoAllMachinesStuff();
  Counter = ++Counter % 5; // increase counter
}

[edit] You had to wait long enough! :D [/edit]