Jump to content
xisto Community
Sign in to follow this  
hitmanblood

Db Problem Probably problem with triggers

Recommended Posts

Hello, I am writing web site using java (jsp) and mysql as database. I need functionality that can be seen in certain online games. For example in Travian when I send soldiers there is time they will arrive in enemy settlement. Now I am interested in this time. How can I fire certain even when time reaches zero. Thing is I studied triggers but problem is that triggers only fire at update and similar events. And I would require something time based.Thanks for your answers.

Share this post


Link to post
Share on other sites

You can use a cron job, but with events I always think differently, why the need of a cron job when you can do something like this:Even though I don't know how you have something done, but I usually don't do jobs, but I only do something when somebody is accessing something, for example somebody send somebody to other town, it will take 7 days in that game, so you have the start date and you just don't do anything, whenever somebody is using script, you calculate everything and show him the latest information, due to you have current time and start time and the time it should have taken.Cron jobs are not always needed in most cases, you just need to think differently about it.Triggers are used on different mysql events, like if you're inserting or updating data in your database, or maybe even selecting, you can do something on that even before or after and etc.

Edited by Quatrux (see edit history)

Share this post


Link to post
Share on other sites

Thanks for answer. I am aware what triggers are used for. But I though it might be solution to problem.And I doubt that cron job would help also. However, the problem is that after time elapses I am required to do certain actions so solution you are proposing wouldn't work. And I used similar solution in several other problems.So this question is still open.

Share this post


Link to post
Share on other sites

the problem is that after time elapses I am required to do certain actions so solution you are proposing wouldn't work.


Explain, why it wouldn't work? after lets say some time elapses, 10 minutes, something happens and who will see it? what will happen? You could give us more information and we would give you a solution, there is nothing impossible, usually you need to change the logic for some processes.

An example of what you want to do would help.

As you said in your first post, I think all you need is to calculate the facts by having different dates and refresh only when if somebody is wishing to see, do something globally, execute a process which would calculate everything you need and only when output. As I said an example with what you want to do and an explanation why this solution is bad would help to think of another solution.

Share this post


Link to post
Share on other sites

Build a QUE of events with start time and time of completion.

 

And I doubt that cron job would help also. However, the problem is that after time elapses I am required to do certain actions so solution you are proposing wouldn't work.

When someone view that town/person or whatever it is, scan the QUE..

1. If an event should appeared to have completed its elapse time, perform the certain actions then remove that event on the QUE

2. Check for next event and go process

3. Go back to number 2 until every event was checked.

4. Add the new event to the QUE and if it needs instant action then perform.

 

So when to process, well basically..

If someone views my profile then process QUE

If I login then process QUE

If I buy something then process QUE

If I attack someone then process QUE

If someone attack me then process QUE

 

 

That is what Quatrux means.

 

Added info:

 

Judging from what you are trying to imply, you want a certain condition to process without loading the screen then use javascript, fire the timers on each load so you can get the actual time and issue an ajax command to do a certain actions

Edited by vhortex (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.