Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Db Problem


4 replies to this topic

#1 hitmanblood

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 788 posts
  • Gender:Male
  • Location:mreža

Posted 09 October 2010 - 10:53 PM

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.

#2 Quatrux

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 605 posts
  • Gender:Male
  • Location:Lithuania, Vilnius
  • Interests:Programming
  • myCENT:49.19

Posted 11 October 2010 - 07:32 AM

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, 11 October 2010 - 07:33 AM.


#3 hitmanblood

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 788 posts
  • Gender:Male
  • Location:mreža

Posted 13 October 2010 - 10:18 AM

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.

#4 Quatrux

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 605 posts
  • Gender:Male
  • Location:Lithuania, Vilnius
  • Interests:Programming
  • myCENT:49.19

Posted 14 October 2010 - 06:54 AM

Quote

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.

#5 vhortex

    Member [Level 3]

  • Kontributors
  • PipPipPipPipPipPip
  • 97 posts
  • Gender:Male
  • myCENT:9.31

Posted 14 October 2010 - 11:29 PM

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

View Posthitmanblood, on 13 October 2010 - 10:18 AM, said:

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, 14 October 2010 - 11:31 PM.





Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users