Forum Topic: getTimer(); Question

(259 views • 11 replies)

This topic is 1 page long.

<< < > >>
None

WindCrazy

Reply To Post Reply & Quote

Posted at: 1/5/08 06:36 PM

WindCrazy LIGHT LEVEL 04

Sign-Up: 12/15/07

Posts: 356

Ok, im using the following code, and i need to make it so that, u have to release the space bar for the code to work again instead of being able to hold it down and it just keeps going up and up

var time:Number = 120;
var hit:Number = 0;

timerVariable=setInterval(function(){
time--;
},1000);

onEnterFrame = function () {
	if(time >= 90) {
		instructions = "Hit The Space Bar Quick!!";
	}
	if(Key.isDown(Key.SPACE)) {
	hit += 1;
	}
}

My Shit Stinks Much Betta Than Yours


None

WindCrazy

Reply To Post Reply & Quote

Posted at: 1/5/08 06:50 PM

WindCrazy LIGHT LEVEL 04

Sign-Up: 12/15/07

Posts: 356

anyone?

My Shit Stinks Much Betta Than Yours


None

WindCrazy

Reply To Post Reply & Quote

Posted at: 1/5/08 07:13 PM

WindCrazy LIGHT LEVEL 04

Sign-Up: 12/15/07

Posts: 356

anyone know how to do this?

My Shit Stinks Much Betta Than Yours


None

Drkgodz

Reply To Post Reply & Quote

Posted at: 1/5/08 07:26 PM

Drkgodz DARK LEVEL 09

Sign-Up: 08/26/06

Posts: 30

var score:Number = new Number(0);
var time:Number = new Number(10000);
timer = setInterval(function(){time-=100;}, 100);

onEnterFrame = function()
{
	if(time>0)
	{
		if(Key.isDown(Key.SPACE) & !sDown)
		{
			sDown = true;
			scored = false;
		}
		if(sDown & !scored)
		{
			score++;
			scored = true;
			trace(score);
		}
		if(!Key.isDown(Key.SPACE) & scored)
		{
			sDown = false;
		}
	}
}

None

WindCrazy

Reply To Post Reply & Quote

Posted at: 1/5/08 07:31 PM

WindCrazy LIGHT LEVEL 04

Sign-Up: 12/15/07

Posts: 356

thanks a lot, ill put u in the interactive games credits

My Shit Stinks Much Betta Than Yours


None

Drkgodz

Reply To Post Reply & Quote

Posted at: 1/5/08 07:35 PM

Drkgodz DARK LEVEL 09

Sign-Up: 08/26/06

Posts: 30

I forgot to mention, change the time variable to change the amount of time you have.


None

El-Presidente

Reply To Post Reply & Quote

Posted at: 1/5/08 07:35 PM

El-Presidente LIGHT LEVEL 27

Sign-Up: 06/02/05

Posts: 5,204

At 1/5/08 07:26 PM, Drkgodz wrote: var score:Number = new Number(0);
var time:Number = new Number(10000);
timer = setInterval(function(){time-=100;}, 100);

onEnterFrame = function()
{
if(time>0)
{
if(Key.isDown(Key.SPACE) & !sDown)
{
sDown = true;
scored = false;
}
if(sDown & !scored)
{
score++;
scored = true;
trace(score);
}
if(!Key.isDown(Key.SPACE) & scored)
{
sDown = false;
}
}
}

1. You don't need the new Number (or whatever new you have) if you ALREADY have var and :Number (or again, whatever you have there). It slows the code down and is repetitive.
2. Put your opening brackets on new lines, so _root.onEnterFrame = function () { .. but closers still keep their own lines...
3. You need &&, because & doesn't work if you just put it alone.
4. Why time -= 100 instead of just making it 100 timer and -= 1.
5. Use == true or == false instead of just repeating the variable's name
6. I would avoid even using &&'s, because you should just make it two openings, so heres an example:
Not As Good:
if(Key.isDown(Key.RIGHT) && sDown == true){
Better
if(Key.isDown(Key.RIGHT)){
if(sDown == true){
}
}

MY E-PENIS IS BIGGER THAN YOURS
8=================================>
...and this is my fag...

BBS Signature

None

WindCrazy

Reply To Post Reply & Quote

Posted at: 1/5/08 07:36 PM

WindCrazy LIGHT LEVEL 04

Sign-Up: 12/15/07

Posts: 356

do u know how to make it so that once u like go u can automatically click it again, because i dont want the pause inbetween cause i want a instant time

My Shit Stinks Much Betta Than Yours


None

Tree-SkyLark-BCE

Reply To Post Reply & Quote

Posted at: 1/5/08 07:41 PM

Tree-SkyLark-BCE LIGHT LEVEL 35

Sign-Up: 08/06/05

Posts: 209

You can use event listeners in AS2. They will probably work better for your purpose:

var time:Number = 120;
var hit:Number = 0;
var listener:Object = new Object();
var spacedown:Boolean = false;

listener.onKeyDown = function()
{
	
	if (Key.getCode() == Key.SPACE)
	{
		if (!spacedown)
		{
			hit++;
		}
		spacedown = true;
	}
}

listener.onKeyUp = function()
{
	if (Key.getCode() == Key.SPACE)
	{
		spacedown = false;
	}
}
Key.addListener(listener);
var timevariable = setInterval(function(){time--;}, 1000);

Here is a link that can explain it:
http://www.nettechnet.org/~jross/?Lectur es:Flash_Actionscript:AS2_-_Event_Listen ers_and_Broadcasters

BBS Signature

None

Drkgodz

Reply To Post Reply & Quote

Posted at: 1/5/08 07:46 PM

Drkgodz DARK LEVEL 09

Sign-Up: 08/26/06

Posts: 30

var score:Number = new Number(0);
var scores:Array = new Array();
var dTime:Number = new Number(1000);
var time:Number = new Number(dTime);
var average:Number = new Number(0);
timer = setInterval(function(){time-=100;}, 100);

onEnterFrame = function()
{
	if(time>0)
	{
		if(Key.isDown(Key.SPACE) & !sDown)
		{
			sDown = true;
			scored = false;
		}
		if(sDown & !scored)
		{
			score++;
			scored = true;
			trace(score);
		}
		if(!Key.isDown(Key.SPACE) & scored)
		{
			sDown = false;
		}
	}else if(time<=0)
	{
		scores.push(score);
		score = 0;
		time = dTime;
		for(i=0;i<scores.length;i++)
		{
			average+=scores[i];
		}
		average = average/scores.length+1;
		average = Math.round(average);
	}
}

This has a variable called average, and a variable caled scores which has all the scores for all the rounds done.


None

authorblues

Reply To Post Reply & Quote

Posted at: 1/5/08 08:46 PM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

At 1/5/08 07:35 PM, El-Presidente wrote: 1. You don't need the new Number (or whatever new you have) if you ALREADY have var and :Number (or again, whatever you have there). It slows the code down and is repetitive.

wrong. its all going to be compiled into bytecode. you have no basis for saying that its "slow" or "repetitive". in fact, its a BETTER practice to do it this way. not necessary, but better.

2. Put your opening brackets on new lines, so _root.onEnterFrame = function () { .. but closers still keep their own lines...

this is a style choice. please dont criticize things that are generally irrelevant. there are many different "schools of thought" that recommend one way or another. there is no difference.

3. You need &&, because & doesn't work if you just put it alone.

correct, but it WILL work. & is the bitwise-and, which will work in this case.

4. Why time -= 100 instead of just making it 100 timer and -= 1.

again, a silly thing to criticize. doesnt make a difference but simplicity of reading.

5. Use == true or == false instead of just repeating the variable's name

unnecessary. doing "== true", in fact, requires that it do one extra check. this is, possibly, the worst of your advice. but hey, lets see what else youve got...

6. I would avoid even using &&'s, because you should just make it two openings, so heres an example:

again, i contend that you have no clue what you are talking about. when the entirety of the AS is converted to bytecode, the two versions you proposed will be converted to the EXACT SAME bytecode. consider the following example:

var nt:Number = 1;
if (false && ++nt);

trace(nt); // output: 1

youll see that the number does not increment because the second portion of the if-statement is never invoked. this will effectively work the same as if you divide it in your asinine way.

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

Drkgodz

Reply To Post Reply & Quote

Posted at: 1/5/08 09:35 PM

Drkgodz DARK LEVEL 09

Sign-Up: 08/26/06

Posts: 30

Authorblues, I was about to say the same thing. As for the timer, I made it go every 100 so you have more of a range to change the time. If it subtracts every second, then if you put the timer value as 1400, it will end up as -400 before it ends. So with 100 you have the thousands place and the hundreds place to put a value.


All times are Eastern Standard Time (GMT -5) | Current Time: 03:40 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!