Spidy:

I'm not a MySQL maven, so I'm going to pretend that you said "Sybase" and leave the conversion effort as an exercise for the reader.... 8^)

First, using your basic idea, you could (on login) compute the number of turns they get for the day. (I'd put a maximum on it, so if they don't log in for a long time they don't get too many turns for a day.) It seems like an appropriate task for the database, so you could do something like this. Given tables something like:

create table users ( user_id varchar(10) primary key, ... --standard junk you already have here turns_left int default 0, last_turn datetime default getdate() ) create table misc ( tag varchar(32) primary key, val varchar(128) ) go insert misc (tag, val) values ('Turns_Per_Day', '5') insert misc (tag, val) values ('Max_Turns_Allowed', '15')
You could use the following procedure when they log into the system:

create proc compute_turns_left @user_id varchar(10) as declare @days integer, @turns, @turns_per_day, @max_turns -- Read the configuration variables select @turns_per_day = isnull(convert(int, val), 1) from misc where tag='Turns_Per_Day' select @max_turns = isnull(convert(int, val), 1) from misc where tag='Max_Turns_Allowed' -- How many days since they last used a turn? select @days=datediff(d,getdate(),last_turn) from users where user_id=@user_id -- Update their turns update turns_left = turns_left + @days * @turns_per_day from users where user_id=@user_id -- And apply the limit cap update turns_left = @max_turns from users where user_id=@user_id and turns_left > @max_turns go
and this one every time they take a turn:
create proc consume_turn @user_id varchar(10) as update users set turns_left = turns_left-1, last_turn=getdate() where user_id=@user_id go
I hope you find this useful.

...roboticus


In reply to Re: Daily Actions by roboticus
in thread Daily Actions by Spidy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.