"Missing variable name in replication definition"... ...No?

Discussions about Coding and Scripting
User avatar
Wormbo
Adept
Posts: 258
Joined: Sat Aug 24, 2013 6:04 pm
Contact:

Re: "Missing variable name in replication definition"... ...

Post by Wormbo »

You're mixing up unrelated concepts. No mention in the replication block only means the server and clients won't exchange data about that.
When the GRI is spawned on the server, its PostBeginPlay() is called (on the server), because that's what happens when actors are spawned. That call actually executes the function (yes, the entire function from start to end), because the GRI's local Role is ROLE_Authority. Granted, when it reaches the if statement, it sees that Level.NetMode != NM_Client and thus skips to the end of the if block, but still the entire function is executed like any other piece of UnrealScript code. The server knows a GRI can be replicated (via Actor replication), because its RemoteRole is > ROLE_None.
When a client connects, the server deems the GRI "relevant" to that client, because it is bAlwaysRelevant, and sends the client the information "hey, spawn a replicated actor of class GameReplicationInfo". When the client spawns it, the newly spawned GRI's PostBeginPlay() is called (on the client), because that's what happens when actors are spawned. That call actually executes the function, because although the GRI's local Role is only ROLE_SimulatedProxy (the replicated spawning automatically swapped Role and RemoteRole before any UnrealScript kicks in), the function is marked as "simulated". Like on the server, the entire function is executed - this time the if statement sees that Level.NetMode == NM_Client and doesn't skip the code inside the if block.

Note how the server and client instances call PostBeginPlay() at entirely different times. Both instances set SecondCount and start a repeating timer at a rate of 0.2 seconds, which will likely fire at entirely different times on the server and its clients. The only difference is (and there's no magic involved here either) that the client will also set all those other variables to empty strings, because on a client the Level.NetMode variable is set to NM_Client for obvious reasons. That's not UnrealScript magic, but a result of the standard if statement reading that variable and comparing it with the NM_Client enum constant.
User avatar
PrinceOfFunky
Godlike
Posts: 1200
Joined: Mon Aug 31, 2015 10:31 pm

Re: "Missing variable name in replication definition"... ...

Post by PrinceOfFunky »

Wormbo wrote:[...] the function is marked as "simulated". Like on the server, the entire function is executed - this time the if statement sees that Level.NetMode == NM_Client and doesn't skip the code inside the if block.
Let's suppose the function hadn't the modifier "simulated", didn't it work the same way?

simulated or not, the function does the same on both of the sides:
It first does the check to see if the function is being called in the proxy actor.
After the check it initialize the SecondCount.
And then it call the Timer function(which Timer function it will call, depends on the actor where the function is in[the proxy for clientside or the original one for serverside]).

I understood the ROLEs, so thank you.
I did read this line:
Marks the function as valid for execution on clients if the actor containing it was replicated to that client and the local role of that client is either ROLE_SimulatedProxy or ROLE_DumbProxy.
Isn't that function called anyway? I meant, even without the "simulated" modifier?
"Your stuff is known to be buggy and unfinished/not properly tested"
User avatar
Wormbo
Adept
Posts: 258
Joined: Sat Aug 24, 2013 6:04 pm
Contact:

Re: "Missing variable name in replication definition"... ...

Post by Wormbo »

UnrealScript distinguishes between calling and executing a function. Function calls do not always result in the function being executed. For example, non-simulated functions on an actor instance with a local Role <= ROLE_SimulatedProxy will not be executed, regardless how you call them. (Dude, read what I link! Seriously!)
Similarly there's the modifier "singular", which prevents execution of the function if the same object instance already executes the same or another singular function.
A replicated function call may even result in all the replication going on, but e.g. a lack of the "simulated" keyword may eventually prevent the function from executing on the target server or client. In fact, functioins that are replicated from a client to the server usually omit the "simulated" keyword. These functions are called on the client for execution on the server. If the replication condition fails, the function would be executed locally on the client, but the lack of "simulated" prevents that. No such protection exists for functions that are supposed to replicate from the server to a client, so those will execute on the server if the replication condition fails.
Post Reply