Skip to main content
Participating Frequently
August 7, 2014
Answered

Date/Time events help

  • August 7, 2014
  • 5 replies
  • 321 views

I'm trying to make vpet like game on flash for class, but I need to work with time and dates for events like feeding, sleep, etc.

At least for now I need help figuring out how to make the game check like every 5 minutes to bring up an alarm about the pet needing food.

Sadly all i have is this:

stop();

const millisecondsPerMinute:int = 1000 * 60;

const millisecondsPerHour:int = 1000 * 60 * 60;

const millisecondsPerDay:int = 1000 * 60 * 60 * 24;

var date1:Date = new Date();

trace(date1);

I get the actual date, but don't know exactly what to do to make it check every 5 minuts or so. Don't know if it's with "if" or "do/while".

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer kglad

don't use the date class, use the timer class.

var feedTimer:Timer=new Timer(5*60*1000,0);

feedTimer.addEventListener(TimerEvent.TIMER,feedF);

feedTimer.start();

// whenever vpet is fed, apply a reset() and start() to feedTimer:

function beenfedF():void{

feedTimer.reset();

feedTimer.start();

}

function feedF(e:TimerEvent):void{

// a feeding was missed

}

5 replies

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
August 7, 2014

don't use the date class, use the timer class.

var feedTimer:Timer=new Timer(5*60*1000,0);

feedTimer.addEventListener(TimerEvent.TIMER,feedF);

feedTimer.start();

// whenever vpet is fed, apply a reset() and start() to feedTimer:

function beenfedF():void{

feedTimer.reset();

feedTimer.start();

}

function feedF(e:TimerEvent):void{

// a feeding was missed

}

koldrageAuthor
Participating Frequently
August 7, 2014

Awesome! Got it to work! Thanks.

Sorry to ask a question slightly out of the topic... How is it that you can save up the current progress? For example if I close the swf it'll go back from the start and I'd have to start it from a baby. I hope I'm not asking for too much. Thanks in advance.

kglad
Community Expert
Community Expert
August 7, 2014

you're welcome.

you can use the sharedobject to save game progress.  you'll need to set your game up to check the sharedobject when your swf starts, it checks the variables you stored (eg, how big your pet is and what tricks it knows) and applies them so you don't start with a newborn pet that knows nothing.