[help]loading vs holding data?

06/20/2011 07:32 taylor2846#1
what would be better to use on my server um im going to use a chars money for an example

1:
the normal way, where the money it saved to the server(NOT THE DATABASE BTW) after loading it.
like int money;
Code:
     int Money
     bla bal everyone nows this way lol

2:
Code:
money{set{save value to mysql}get{get teh value from mysql} }
3:
or the way that i am doing it now here is an example.
Code:
     private int _mny
     public int Money
     {
     get  return _mny 
     set  _mny = value; Save_Money_To_MySql 
     }
btw all stuff saves ad it changes well not mapid,x,y
other then that if anythign changes on a char or a item of that chars it changes in the database.

so wht do you all thank i should do here and please give me some reasoning why.
06/20/2011 07:35 Spirited42#2
Quote:
Originally Posted by taylor2846 View Post
what would be better to use on my server um im going to use a chars money for an example

1:
the normal way, where the money it saved to the server after loading it.
like int money;


2:
money{set{save value to mysql}get{get teh value from mysql} }

wht im doing as of now is like 2 but with out loading form mysql each time got a money int else where to hold the data.

but what do you all thank i should do and please give me some reasoning.


btw all stuff saves ad it changes well not mapid,x,y
other then that if anythign changes on a char or a item of that chars it changes in the database.

so wht do you all thank i should do here and please give me some reasoning why.
#1 and #2. Load it to the server using MySql and then save it. When it changes... save it to MySql. Accessing money and variables like that will cause lag on your server.
06/20/2011 07:40 taylor2846#3
what do you mean?
saving something every time it changes like money
or the get/set

{edit}
so you mean the way im doing it?
like this?
Code:
     private int _mny
     public int Money
     {
     get  return _mny 
     set  _mny = value; Save_Money_To_MySql 
     }
btw thats just an example but is that how you are saying 2 do it ?
if so good xD because thats the way i have been doing it lol

going to bed now its late/early how ever you wana say it lmao i will be on to see wht you all say here moro if i get the time to do so.
06/20/2011 08:08 Y u k i#4
private int _mny
public int Money
{
get return _mny
set _mny = value; Save_Money_To_MySql
}

is the way to do it. You might wanna add The UpdatePacket for Money aswell.
06/20/2011 13:01 Spirited42#5
Quote:
Originally Posted by Y u k i View Post
private int _mny
public int Money
{
get return _mny
set _mny = value; Save_Money_To_MySql
}

is the way to do it. You might wanna add The UpdatePacket for Money aswell.
that's how I do it too.
06/20/2011 13:19 Korvacs#6
Code:
public int Money { get; set; }
Is the best way to do it nowadays, unless you need to do something like this when you set the value:

Code:
        //Completely Madeup Example

        private int m_Money;

        public int Money
        {
            get { return m_Money; }
            set
            {
                m_Money = value;
                Database.SetValue("Money", value);
                Client.Send(UpdatePacket(Updates.Money, value));
            }
        }
In which case that is the only way to do it.
06/20/2011 15:22 taylor2846#7
should i add a check in it so that way if a player is not loaded then it does not save to database?

because if you do the get set like you did above me when you are loading the player it would also save the players stuff.

would that matter or should i add something like if char is loaded?
06/20/2011 15:32 Korvacs#8
Quote:
Originally Posted by taylor2846 View Post
should i add a check in it so that way if a player is not loaded then it does not save to database?

because if you do the get set like you did above me when you are loading the player it would also save the players stuff.

would that matter or should i add something like if char is loaded?
You could add a check in the database method used to save the value yes, although i doubt its really necessary to be honest, the sql server wont be doing enough work to slow it down by performing these extra queries, and also the check will be performed everytime the value changes.
06/20/2011 18:08 _DreadNought_#9
Check impulse's source, Amazing example there. Entity.cs
06/20/2011 21:05 Spirited42#10
You should flag what the entity is if monsters and players are going to share the packet. Make a byte const and have it so it checks what it is (that way it doesn't try to save things to the database as a monster- monsters do use update packets too!). Update packets shouldn't be activated until the entity is loaded (same with saving to the database) so have a bool too. Good luck.

Resources:
Impulse's Public 5165 Source
Project Exodus
06/20/2011 23:02 taylor2846#11
ok thanks for the info everyone.