Is it acceptable to send a MySQL query OnPlayerUpdate?
#5

Quote:
Originally Posted by Prostilov
Посмотреть сообщение
The purpose of me sending a SELECT statement every player update is to determine in what zone they currently are. Zone coordinates are saved in a MySQL table, so it runs through it to check that.
In programming, theres a thing called "variable". You create it in the script, and then you can use it to store certain data directly in RAM for fast access.
Then theres the "database". It also stores data, but normally isnt accessed directly, but via queries to the database manager. These queries are translated to access some specific data in the database. This process takes a little while. Depending on several details, accessing a database is about 10,000 to 1,000,000 times slower than accessing a variable.
And thats why you should use databases only for the stuff that you really cant store in variables.


Imagine a piece of paper laying in front of you on the desk. You can easily read it, or write on it whatever you like. It would then be a variable. Or you can call your assistant, describe him exactly what piece of paper youre talking about, where to find it, and what to write on it, or what part to read from it. Then you would wait for him to enter the room, find the paper using your descriptions, write to/read from it, leave the room, and call you back to report that hes done with your task. In that case, the piece of paper would be a database.
If you use a database in OnPlayerUpdate, your assistant would have to do this hundreds of times every second. Hed probably quit his job after just a few seconds, or die from exhaustion in 2 minutes. And you couldnt do your own work, because hed constantly be messing around on your desk. And slamming the door at such a high frequency that the slam sounds merge into a seriously annoying beep that pitches up and down as players enter and leave your server.


Just use a global variable and save both your assistant and your nerves.
Код:
new zoneCoordinates[MAX_ZONES][4];
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)