Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm beginning to implement a simple scripting system into my networked server, and I've hit a snag. Before, I've been wrapping my calls into functions on objects that manipulate objects, but lately I've been finding this to be a pain for simple things. For example, if I set 'player.HP = 1'.. this works server-side. But the player side never sees this change unless I explicitly send a packet to inform the client.

For many things like map swapping that require more complicated changes, like change X, Y, Map and do this.. I have a function. That's fine. But what about these small properties I want to sync?

share|improve this question
1  
It's fairly common to use a code generator and a DDL to automate the handling of replicated properties. The main code simply includes the generated file while the replication is handled by the net code built into what the code generator made for you. –  Patrick Hughes Jun 30 '12 at 22:24
    
Any examples, Patrick? I've not seen that in middleware or in free engines, nor the one I worked with commercially. –  Kylotan Jul 1 '12 at 18:10
add comment

1 Answer

up vote 0 down vote accepted

if I set 'player.HP = 1'.. this works server-side. But the player side never sees this change unless I explicitly send a packet to inform the client.

So... explicitly send a packet to inform the client. Not from within the script, from the code that manages the property changes.

On a very basic level, you can send an update message whenever you change a property. Just make sure your property changing mechanism stores the changes, and send out those changes when appropriate.

Another way is to give these properties dirty flags. Set the flag when you change a property, and periodically you check all the properties to see if any are dirty. Copy the new values of the dirty properties into a message, send that message to the client, then clear the dirty flag.

share|improve this answer
    
I guess I should have been a little more clear... I'm trying to look for a little more automated way to do this without polluting the Player class with logic. And I really don't want to create a new packet for every single property. I thought of: Mark properties that need syncing with a 'Sync' attribute. Call perhaps a 'PropertyChanged' on all of them.. and write their underlying values. I guess that's not so bad, if the performance is right. Dirty flags is a lot of extra code. –  Vaughan Hilts Jun 30 '12 at 18:58
    
This is an automated way, and doesn't have to alter the Player class except for wrapping the relevant properties. Nor does it require a new packet for each property - why would it? Your 'sync' approach doesn't sound much different from a dirty flag so I'm not sure what that gains. –  Kylotan Jul 1 '12 at 18:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.