PDA

View Full Version : long lines of a/s



charlie
May 8th, 2003, 03:52 AM
ok this is a bit of a simple one.
I have a really long line - in actuality a long if() statement
In VB you can break long lines (for ease of reading) by adding an underscore at the end of the line and continuing in the next line down.
is there a simple way of doing this, or should i just put up with the really long line?

ps a sample of the code is...

if (_level1.getBytesTotal()>0 && _level2.getBytesTotal()>0 && _level3.getBytesTotal()>0 .....
continuing on to _level13

brainy
May 8th, 2003, 03:55 AM
i think you could just break the lines... that shouldn't bother the interperter. line breaking is just for ease of reading anyways, an entire script could be just one long line. i think you can break about anywhere you want...

charlie
May 8th, 2003, 03:59 AM
do you mean break using ; or literally just start on a new line (in actual fact i have tried both and neither works), not sure if this is because it's all within the if( ), i mean i could just nest another few if statements, which would work too.
And yes it is only to make my code tidier, so ultimately not of shattering importance.

kode
May 8th, 2003, 05:30 AM
for (i=1; i<=13; i++) if (this["_level"+i].getBytesLoaded()) ii++;
if (ii == 13) {
yourActionsHere();
}
a bit unorthodox... but it should work. :P

charlie
May 8th, 2003, 05:58 AM
thanks kax, after a bit of tweaking it appears to work. :)

kode
May 8th, 2003, 06:00 AM
no problem, charlie. =)

brainy
May 8th, 2003, 06:45 AM
how about this?

while (!woop && (i<14)) woop = (this["_level"+(i++)].getBytesTotal() > 0);
if (woop) {...}

just trying ;)

kode
May 8th, 2003, 06:55 AM
nope... that doesn't work.

brainy
May 8th, 2003, 07:11 AM
ofcourse not, silly me. i meant this:

while (!woop && (i<14)) woop = !(this["_level"+(i++)].getBytesTotal() > 0);
if (!woop) {...}

kode
May 8th, 2003, 07:20 AM
you just changed a boolean from true to false... still doesn't work.

brainy
May 8th, 2003, 07:23 AM
why doesnt it work?



and i changed two.

kode
May 8th, 2003, 07:38 AM
you tell me...

// array to simulate the levels
var levels = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
// brainy
while (!woop && i<14) woop = !(levels[i++]>0);
if (!woop) trace("brainy");
// kax
for (k=1; k<=13; k++) if (levels[k]>0) kk++;
if (kk == 13) trace("kax");
and you just changed one boolean, is there any other boolean besides woop? ;)

brainy
May 8th, 2003, 07:49 AM
you're right. i was being silly again. need to change 1 boolean, and it works:


while (!woop && (i<14)) woop = !(this["_level"+(i++)].getBytesTotal() > 0);
if (woop) {...}

kode
May 8th, 2003, 07:52 AM
nope... you still don't get it. :-\

brainy
May 8th, 2003, 11:10 AM
but it works! i tested it and stuff. well, either it works right, or completley the opposite,. its doing *something* right, im sure :P

kode
May 8th, 2003, 11:14 AM
no, it doesn't!! :P