1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. 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.

Server/Client Timers

Discussion in 'Ask a Coder' started by SoSilencer, Oct 9, 2001.

  1. SoSilencer

    SoSilencer Harry Goz (1932 - 2003)

    Joined:
    Nov 27, 2000
    Messages:
    834
    Likes Received:
    0
    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?
     
  2. Wormbo

    Wormbo Administrator Staff Member

    Joined:
    Jun 4, 2001
    Messages:
    5,911
    Likes Received:
    35
    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]
     

Share This Page