Forum BigDB Day Timer

Discussion and help relating to the PlayerIO database solution, BigDB.

Day Timer

Postby Balance026 » April 13th, 2015, 12:49 pm

Hey ! I already read yahoo gamesnet documentation, i found something but it doesn't have good explanation and i never figured out how can i set a date like this.. For example i want to setup a timer that you can feed your pet 1 per day and the next day he will be able to do it again after 24 hours... I can't find something that i can understand !
Balance026
 
Posts: 6
Joined: April 7th, 2015, 9:26 am

Re: Day Timer

Postby robscherer123 » April 13th, 2015, 2:43 pm

All you would have to do was save a database objects that saves a variable called "lastFed" which stores the date time that the pet was last fed. Then, whenever the player goes to feed the pet next, you load that database object and check if 24 hours past since the current date time.

On your server, you would use the code below to mark the current time (in UTC time) that the pet was last fed on a database object.

Code: Select all
DateTime theDateCreated = DateTime.Now;
myDatabaseObject.Set("dateFed", theDateCreated.ToString());


Then, you would use the following code to check the the time that has past the next time the player feeds the pet.

Code: Select all
DateTime lastFed = Convert.ToDateTime(lastFedDatabaseObject.GetString("dateFed"));
TimeSpan timeSpan = DateTime.Now - lastFed;

if (timeSpan.TotalDays >= 1) {
    //Player may feed the pet, one day has past.
} else {
    //Cannot feed pet, not enough time has passed.
}
robscherer123
Paid Member
 
Posts: 309
Joined: December 12th, 2012, 8:46 pm

Re: Day Timer

Postby Balance026 » April 14th, 2015, 4:31 am

Wow , thank you very much for your good explanation ! Now i can continue .... 8-)
Balance026
 
Posts: 6
Joined: April 7th, 2015, 9:26 am


Return to BigDB



cron