Quote:
Originally Posted by Vince
The id stored in the database is only there to uniquely identify that particular row. It does not have any intrinsic value. In the houseInfo enum you should add another attribute "databaseID" or something like that to store this id. When you go to update you use that value, NOT the array index.
However, to me it always seems silly to duplicate the data to the gamemode when it's already stored in the database. In many cases you can and should go directly to the database.
|
I have always been doing it this way, and it's is because sa-mp is single threaded - aka it would use more resources reading from the database all the time. I would think of the database as a place where i save all the data in order to re-use it next time my server runs. And ofc, when a player leave i would save his data too.
This is why I'm doing it this way, however, I would still need to save the id's into an array I guess, in order to make my system function, as I just re-created it using this method (it was based on pickup id's before, and it totally fucked up the id's at times.)
Quote:
Originally Posted by AmigaBlizzard
I would remove the auto-increment from your ID column.
When I create a house, I try to add the data to the array itself before adding it to the database.
That one is easy because you can just loop through your array from 1 to 1999 (I'm not using HouseID 0 in my scripts) and find a free spot.
When there is room to add a house (you have less than 2000 houses), add the data to the array.
When that's done, save the data to the database, using the array-index as HouseID.
No need to use auto-increment in the database, no worries about ever getting higher HouseID values above your MAX_HOUSES variable.
And when you update/delete a house on the server, you can directly use the array-index as this IS the HouseID.
HouseID's previously created and deleted will be used again when you create a new house.
Let's say you have 500 houses and you delete HouseID 371.
This means you have a gap (empty space) in your array at index 371.
The next time you create a new house, it will use this free spot to create a new house.
Auto-increment should only be used for players in my opinion, and probably house-vehicles (data that cannot link directly to an array-index).
|
Thanks alot, this sounds like a wonderful way to do it!
But, the auto-increment row is also the Primary key row, so I would need it anyway to be able to do changes in the database.
I guess creating another row could work, or just re-use the Pickup-ID row for this (as it isn't used atm).
Quote:
Originally Posted by PrO.GameR
Well isn't sa-mp single threaded ? In many cases using ram to avoid cpu usage is way better, and sometimes you just need the data in the second, not as soon as the database query finishes (the callback)
OT: I used to have AI id of the sql as my array index too, but realized it's not a good idea, therefore I started saving it in one of the array vars and auto incremented the array index myself, hope this helps you
|
Yeah good idea about the array, seem much like what Amiga said
How would you load the houses into the arrays?
EDIT nvm, I figured out how, thanks alot for your help everyone!
I learnt something new, that's what i love