Newgrounds.com — Everything, By Everyone.

Checking login status…

USERNAME:

PASSWORD:

Logging in…

Logged in as:
.
Logging out…
Inbox My Account Log Out


Forum Topic: Booleans

(282 views • 38 replies)

This topic is 2 pages long. [ 1 | 2 ]

<< < > >>
None

Nuggs

Reply To Post Reply & Quote

Posted at: 6/3/08 05:53 PM

Nuggs LIGHT LEVEL 18

Sign-Up: 12/17/05

Posts: 1,205

This is the nesting the ifs is the fastest way to do it.

if(_root.contact2 == true) {
     if(hitTest(_root.next)) {
          _root.nextFrame();
     }
}

Games|1|2|3| Movies|1|2|

BBS Signature

None

GuyWithHisComp

Reply To Post Reply & Quote

Posted at: 6/3/08 05:54 PM

GuyWithHisComp LIGHT LEVEL 23

Sign-Up: 11/10/05

Posts: 4,028

Also,

= is for assigning
== is for checking equality

BBS Signature

None

Swordsbite

Reply To Post Reply & Quote

Posted at: 6/3/08 05:56 PM

Swordsbite NEUTRAL LEVEL 08

Sign-Up: 03/10/08

Posts: 639

nope it wasnt the variable lol, i had everything backwards and now it works, cause i tried it that way with the old variable too XD

thats ok Shirk

Footsteps of zrb || As:Main || As3:Main || Flash Tutorials || PM me for help. ||


Goofy

zrb

Reply To Post Reply & Quote

Posted at: 6/3/08 06:00 PM

zrb LIGHT LEVEL 08

Sign-Up: 08/08/06

Posts: 3,740

nope it wasnt the variable lol, i had everything backwards and now it works, cause i tried it that way with the old variable too XD

Ah, ok then xD

thats ok Shirk

Or is it.. : O

I can speak french :3 || As :Main || As3: Main || Animation: Main || Flash Tutorials ||

BBS Signature

None

GuyWithHisComp

Reply To Post Reply & Quote

Posted at: 6/3/08 06:02 PM

GuyWithHisComp LIGHT LEVEL 23

Sign-Up: 11/10/05

Posts: 4,028

At 6/3/08 05:53 PM, Nuggs wrote: This is the nesting the ifs is the fastest way to do it.

In what way is it faster?

BBS Signature

None

Swordsbite

Reply To Post Reply & Quote

Posted at: 6/3/08 06:02 PM

Swordsbite NEUTRAL LEVEL 08

Sign-Up: 03/10/08

Posts: 639

At 6/3/08 05:54 PM, GuyWithHisComp wrote: Also,

= is for assigning
== is for checking equality

Thanks GWHC, i understand that now. And Nuggs or whatever, you just copied the code and you said it lol

Footsteps of zrb || As:Main || As3:Main || Flash Tutorials || PM me for help. ||


None

Nuggs

Reply To Post Reply & Quote

Posted at: 6/3/08 07:16 PM

Nuggs LIGHT LEVEL 18

Sign-Up: 12/17/05

Posts: 1,205

At 6/3/08 06:02 PM, GuyWithHisComp wrote:
At 6/3/08 05:53 PM, Nuggs wrote: This is the nesting the ifs is the fastest way to do it.
In what way is it faster?

Read this article

Here

9) Using nested if
Whenever using complex conditional expressions you can optimize the code by breaking them into single nested conditions.
This way you don't have to evaluate all the expressions all the times.
The following code is what we used for the benchmark: even if the conditional expressions are pretty simple the speed increse is significant.
Also you can notice that the expression that evaluates as false is in 3rd position, so you may even get better performance when it is placed in 2nd or 1st position.

MAX = 20000
a = 1
b = 2
c = -3
d = 4

var i=MAX
while(--i > -1)
{
	if (a == 1 && b == 2 && c == 3 && d == 4)
	{
		var k = d * c * b * a
	}
}


var i=MAX
while(--i > -1)
{
	if (a == 1)
	{
		if (b == 2)
		{
			if (c == 3)
			{
				if (d == 4)
				{
					var k = d * c * b * a
				}
			}
		}
	}
}

Games|1|2|3| Movies|1|2|

BBS Signature

None

GuyWithHisComp

Reply To Post Reply & Quote

Posted at: 6/4/08 02:20 AM

GuyWithHisComp LIGHT LEVEL 23

Sign-Up: 11/10/05

Posts: 4,028

At 6/3/08 07:16 PM, Nuggs wrote:
At 6/3/08 06:02 PM, GuyWithHisComp wrote:
At 6/3/08 05:53 PM, Nuggs wrote: This is the nesting the ifs is the fastest way to do it.
In what way is it faster?
Read this article

I just tested it out and it does make a small speed improvement.

But not for the reason they say.

Flash does not evaluate all expressions just because they are nested in the same statement.

Try

function a():Boolean
{
	trace("a");
	return false;
}
function b():Boolean
{
	trace("b");
	return true;
}

( a() && b() );

And you'll see only a() is evaluated because it returns false.

BBS Signature

None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 6/4/08 02:46 AM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 9,232

Argh stop talking about efficiency with AS2. It's a useless argument. AFTER ALL, it took me three days to come up with a more efficient interpreter with no experience. That was recursive. Srsly.

haXe AliceML Box2dLite Learn AS
#ngprogramming at irc.freenode.net
OVER NINE THOUSAAAAND!!!


All times are Eastern Daylight Time (GMT -4) | Current Time: 06:48 AM

<< Back

This topic is 2 pages long. [ 1 | 2 ]

<< < > >>
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!