Long PHP script

Associate
Joined
24 Oct 2002
Posts
980
Location
Manchester
I am writing an online game and progressing nicely with PHP and MySQL (of course)

I need a script to run in the background that processes player positions, combat and stats etc which is getting quite long and difficult to read.

What is the best way to handle a large script? I've tried using includes but due to some looping they were getting messy and caused more errors than it was worth as I've not got an environment I can debug so I'm a notepad developer.

The script is triggered by ajax so the length of time it runs for doesn't bother me and there is no direct return to the client either.

It's just getting a bit difficult to read and manage.

Any tips?
 
Sorry about not replying sooner.

I'm only at 350 lines so it's by no means mammoth, it's just hard to follow.

The game has characters on a map that can move around independently, the script needs to run every 2-10 seconds to update player positions and calculate attacks etc so and as attacks depend on the order of movements and entering/leaving buildings etc is done, they all have to be handled in the order requested. There is a command queue table which the script works through for an amount of time before relinquishing a lock on the queues so another process can do some work.

The script is sent by ajax precisely because it has no response by design, the client will not know they are running it. CRON can only run hourly but I'm not allowed a continuous process on my hosting package so lots of discrete runs that do not affect the clients was the way to go.

I guess I'm struggling with scope putting everything in functions as there are so many variables flying around governing movements and attacks, functions were 5 lines long but needed 10 parameters or an object. I've not really got into writing classes as I haven't felt the need yet.

I can't put the game online yet to demonstrate as it's a reasonably unique idea and I don't want to be pipped to the post but really just talking about it has helped.


PS I'm still using one big script at the moment as sometimes OO is just more work than it's worth.
 
Back
Top Bottom