Advanced counter functions

Started by , Tue 13/03/2007 10:33:20

Previous topic - Next topic

m0ds

Hello, I just need a small word of advice. I've got a counter in my game which is recording the day, month and year. I'm trying to make it so that something can happen on a date I choose, for example the second day of the seventh month of the year 2000. That part is easy enough.

But then I want the system to somehome indicate to itself that 20 days after that date, whatever was made to happen originally can then be stopped. So for example, lets just say it plays some music for 20 days.

I know I can simply stop it by choosing a specific date that the counter reaches, but need it to do it under any instance, so I can call any date and it will always then cancel the action 25 days later.

Any pointers? I hope that made some sense! I'm in college so I can't post up the code just yet, but I'd appreciate any help :)

Ashen

Do you have the first bit already coded, or do you just mean it's easy enough in theory? If you've got it coded, show it - it's easier to work with that, than to give you an answer that might not work with what you've got. Also, is it 'real' time, or some sort of game time? (I guess game time, since you use 2000 as an example date.)

As a general suggestion, you could store the DateTime.RawTime value of the date the event is triggered, the keep comparing it to a value for 20/25 (whichever you actually want) days later.

If you use game time, I think you'll need to have some equivalent to DateTime.RawTime that you figure your dates from - you should be able to use that in the same way. (And if you don't have one, you could possably add it.)

Code: ags

// int StartTime = 962531380; (July 7th, 2000)
// 20 days = 1728000 seconds
// int EndTime = StartTime + 1728000;

// repeatedly_execute
DateTime *dt = DateTime.Now;
if (StartTime != 0 && dt.RawTime >= EndTime) {
  // Cancel event stuff
  StartTime = 0;
}
I know what you're thinking ... Don't think that.

m0ds

Thanks, well I can definitely see what you're getting at in that code, Ashen. I do already have the first part coded, it's a working counter++ method but it isn't using the DateTime function, a day is converted into an integer, so I rather its done through comparing values. It's game-time too, and all months are 30 days long at the moment :P

Again not sure if that makes sense. It's quite hard to explain! I'll post the code up later. Cheers again!

SMF spam blocked by CleanTalk