Wednesday, August 29, 2007

Do, undo, rethink, redo and I feel much better

So this is my first shot using JSON. I use JSON to return events data back to the client. At first, I thought the best way would be to create classes for each events. Well, it didn't take long before I realized it was way too much work to maintain.

Well, it's the best way to learn. So now, I switched to use arrays instead. Before, it sometimes happened that an object was sent to the client with 1 or more empty properties. First, it was not really smart bandwidth wise. Second, I felt dirty.

With arrays, I'm now sure that only what's needed is sent to the client. And on top of that, it becomes much more easier to add more info if a change needs to be done. Each event possess its own function and I wrapped them all inside a class named EventManager. I will probably save a lot of time coding the client since I will only need to refer to this class.

So before, I had something like this (inside ZoneManager):

objZoneEvent.obj = paramobj
objZoneEvent.nme = paramname
objZoneEvent.x = paramx
objZoneEvent.y = paramy

objGameEvent.EventType = eventType.
objGameEvent.EventDatetime = Now
objGameEvent.DataReturned = objZoneEvent


And now (inside EventManager):


objGameEvent.EventType =
objGameEvent.EventDatetime = Now
objGameEvent.DataReturned = arrrayEventData


I know, it might not sound very interesting to you but it is for me. I just made a whole part of the framework a lot easier to handle. Of course, it means I have to revise parts of what I have done until now but it's part of the game. Better now than later, thanks to my interface prototype.