Net ForcingNet forcing is a fairly important concept in creating multiplayer compatible ages. As its name implies, Net Forcing makes Uru "force the action over the network."
With that in mind, here is a simple method of showing netForcing in action.
- Code: Select all
#This make the user invisible to himself only
avatar = PtGetLocalAvatar()
avatar.draw.netForce(0) #Do not send over network
avatar.draw.disable()
#This make the user invisible to everyone
avatar = PtGetLocalAvatar()
avatar.draw.netForce(1) #Send over network
avatar.draw.disable()
Now, let's move on to more complicated aspects of net-forcing. While sending updates to all the remote clients is indeed useful, it introduces a layer of complexity. Let's take a look at some ptAttributes (values passed to a python script via the plPythonFileMod)
- Code: Select all
Activator = ptAttribActivator(1, "Activator: The Clickable", netForce=1) #Clickable object
Responder = ptAttribResponder(2, "RespMod: The Responder", netForce=0) #Action to run
LocalResp = ptAttribResponder(3, "RespMod: Local Responder (Easter Egg -- a stupid one)", netForce=0)
Now, to briefly explain, the ptAttribute automatically has netForcing disabled, so (for example), if I did not override the netForce=0 on the "Activator" variable, then if User X clicked the clickable, then User Y wouldn't know it; however, because netForce is set to true, then User Y will know when User X toggled the clickable.
Now, consider the following code OnNotify method for the above ptAttributes:
- Code: Select all
def OnNotify(self, state, id, events):
if(id == Activator.id and state):
#Everyone in the age will execute this when anyone toggles the clickable
Responder.run(self.key)
if PtWasLocallyNotified(self.key):
#Only the person who clicked will come here
RespLocal.run(self.key)
Now everything should begin to make sense. When User X clicks on Activator, then everyone will run Responder which is NOT net forced... If it were, then everyone in the age would loop that action times the number of people in the age (because it was getting run on everyone in the age by each person in the age... Brain explosion yet? Yes? Good! That means you're doing as well as I did.). Finally, the user who clicked the Activator will see the RespLocal action, which is not netForced either (so only he can see it).