I don't need to test my programs. I have an error-correcting modem.

Difference between revisions of "Talk:Everything you ever wanted to know about replication (but were afraid to ask)"

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search
(So if I get this right....: new section)
Line 1: Line 1:
 
Ah sorry for changing that i thought dynamic would make more sense and have still the same meaning so i dealt with it just like typos and adding categories to someone else his article. --Eliot 19:28, 13 August 2010 (UTC)
 
Ah sorry for changing that i thought dynamic would make more sense and have still the same meaning so i dealt with it just like typos and adding categories to someone else his article. --Eliot 19:28, 13 August 2010 (UTC)
 +
 +
== So if I get this right.... ==
 +
 +
Ok if I understand this correctly:
 +
 +
1. The <uscript>replication{}</uscript> block is used to update variables on the client(s). When this happens, depends on the variable used in the if-statement (ie bNetInitial) surrounding the variable.
 +
 +
 +
 +
2. To execute something after a variable is updated, mark the variable for replication notifications using 'repnotify': <uscript>var repnotify int myRepInt</uscript>
 +
This calls the <uscript>simulated event ReplicatedEvent(name VarName)</uscript> function.
 +
<uscript>simulated event ReplicatedEvent(name VarName)
 +
{
 +
    if(VarName == 'myRepInt')
 +
    {
 +
        myActionOnRepIntChange();
 +
    }
 +
    else
 +
    {
 +
        super.ReplicatedEvent(VarName);
 +
    }
 +
}</uscript>
 +
 +
 +
 +
3. If we execute a function on the client (function has to be marked simulated for this) and it needs to be done on the server aswell (to update/notify change to all others),
 +
we need a reliable (or unreliable if it's not that big of a deal if it doesn't happen) server function (containing the same logic as the client function).
 +
<uscript>
 +
exec setMyRepInt()
 +
{
 +
    initMyRepInt();
 +
}
 +
 +
simulated function initMyRepInt()
 +
{
 +
    myRepInt = 10;
 +
 +
    if(Role < Role_Authority)
 +
    {
 +
        serverInitMyRepInt();
 +
    }
 +
}
 +
 +
reliable server function serverInitMyRepInt()
 +
{
 +
    myRepInt = 10;
 +
}
 +
</uscript>
 +
 +
I hope this is correct and that if it is the code may enhance the tutorial/QA/overview of replication for others.

Revision as of 11:49, 12 October 2011

Ah sorry for changing that i thought dynamic would make more sense and have still the same meaning so i dealt with it just like typos and adding categories to someone else his article. --Eliot 19:28, 13 August 2010 (UTC)

So if I get this right....

Ok if I understand this correctly:

1. The

replication{}

block is used to update variables on the client(s). When this happens, depends on the variable used in the if-statement (ie bNetInitial) surrounding the variable.


2. To execute something after a variable is updated, mark the variable for replication notifications using 'repnotify':

var repnotify int myRepInt

This calls the

simulated event ReplicatedEvent(name VarName)

function.

simulated event ReplicatedEvent(name VarName)
{
    if(VarName == 'myRepInt')
    {
        myActionOnRepIntChange();
    }
    else
    {
        super.ReplicatedEvent(VarName);
    }
}


3. If we execute a function on the client (function has to be marked simulated for this) and it needs to be done on the server aswell (to update/notify change to all others), we need a reliable (or unreliable if it's not that big of a deal if it doesn't happen) server function (containing the same logic as the client function).

exec setMyRepInt()
{
    initMyRepInt();
}
 
simulated function initMyRepInt()
{
    myRepInt = 10;
 
    if(Role < Role_Authority)
    {
        serverInitMyRepInt();
    }
}
 
reliable server function serverInitMyRepInt()
{
    myRepInt = 10;
}

I hope this is correct and that if it is the code may enhance the tutorial/QA/overview of replication for others.