Hi!
I’m currently making some sort of FNAF game at the minute, where you look at cameras and different characters move around. I’m having some trouble with the AI.
You see, I’ve got a timer set up for each character. The timer selects a random number within a range, and then counts down. When it hits 0, a variable switches from false to true, and the character moves to a different room. This seems to work perfectly fine, however, once that timer ends, I would like another timer to start, using the exact same code. In other words, I want the code to follow a set path. So, once a piece of code has been executed, it moves onto the next piece, and so on.
Is there any way to do this in AS3?
Yes, but how do I link that timer to the previous timer code?
This is the timer code I have:
var fl_SecondsToCountDown_2:int = 60 + int(Math.random() * 60);
var fl_CountDownTimerInstance_2:Timer = new Timer(1000, fl_SecondsToCountDown_2);
fl_CountDownTimerInstance_2.addEventListener(TimerEvent.TIMER, fl_CountDownTimerHandler_2);
fl_CountDownTimerInstance_2.start();
function fl_CountDownTimerHandler_2(event:TimerEvent):void
{
if (fl_SecondsToCountDown_2 <= 1) {
TOILETS_MOVE = true;
TOILETS_TIMER = true;
BACKSTAGE_MOVE = false;
SHOWSTAGE_MOVE = false;
KITCHEN_MOVE = false;
RIGHTHALL_MOVE = false;
LEFTHALL_MOVE = false;
SPAREROOM_MOVE = false;
}
trace('SECONDS UNTIL MOVEMENT - ' + fl_SecondsToCountDown_2);
fl_SecondsToCountDown_2--;
}
//STOP CODE
//*************************************************************************
// **NEXT TIMER GOES HERE**
After that timer has been run, can I stop that code and make it move onto the next timer?
Not sure if you still need help with this, but there is also an event called TIMER_COMPLETE that is triggered when a timer has run out.
You could do something like this:
fl_CountDownTimerInstance_2.addEventListener(TimerEvent.TIMER_COMPLETE, restartTimer);
function restartTimer (event:TimerEvent):void
{
var randomCountDown:int = 60 + int(Math.random() * 60);
var newTimer:Timer = new Timer(1000, randomCountDown);
newTimer.addEventListener(TimerEvent.TIMER, fl_CountDownTimerHandler_2);
newTimer.addEventListener(TimerEvent.TIMER_COMPLETE, restartTimer);
newTimer.start();
}