-
suvat
[RESOLVED] action occuring after a set amount of time.
how is this done?
im assuming "getTimer();" is used and "random();"
but in what context?
something like:
code:
_root.onEnterFrame = function() {
timer = getTimer()/1000;
if ((timer) = .25) {
do action
}
}
};
where does the random number code go#
basically i want the timer to start counting down from a random time of max about 3 seconds until it reaches 0.then an action occurs
any help is appreciated
thanks
cobhc
-
Maybe try something like this...
Code:
//
function getRand(maxNum, minNum) {
return Math.floor(Math.random() * (maxNum - minNum)) + minNum;
}
//
var startTime = getTimer();
var limitTime = getRand(3, 1) * 1000;
_root.onEnterFrame = function() {
if (getTimer() - startTime > limitTime) {
//do action
trace("time's up!");
delete this.onEnterFrame;
}
};
-
suvat
your a saint that works perfectly!!!
thanks so much!
cobhc
-
suvat
just encountered a major problem
as this event occurs after a random amount of time (ive included a demo of my game this time so it can be more specifically related) it stops all the other code within the _root.onEnterFrame instance.
i think its something to do with the delete this.onEnterFrame function?
thanks
rory
the example
-
Yes, if you are using the _root.onEnterFrame for other things, the time out will stop them. The modified code below eliminates this problem.
Code:
//
function getRand(maxNum, minNum) {
return Math.floor(Math.random() * (maxNum - minNum)) + minNum;
}
//
var startTime = getTimer();
var limitTime = getRand(3, 1) * 1000;
var runTime = true;
_root.onEnterFrame = function() {
if (runTime) {
if (getTimer() - startTime > limitTime) {
//do action
trace("time's up!");
runTime = false;
}
}
};
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|