Boolean Values That Use && || &&

I am trying to set up if function like this.

my current song position >=1 and my current song position <2
play song 2

You write it like this

if (song.position >=1 && song.position <=2){
gotoandplay(100)

I would like to add another set of paramiters

my current song position >=3 and my current song position <4
play song 2

I have tried to write it like this

if (song.position >=1 && song.position <=2 || song.position >=3 && song.position <4 ){
gotoandplay(100)

The code above does not work. What am I doing wrong?

Did you try using “or” instead of “||”

If it doesn’t work, don’t mind me, I don’t know what I am talking about. ::slinks into corner::

try using brackets so that your order of operations in the if statement is explicit. flash evaluates && before ||.

trace(false && false || true);
// traces true

trace(false && (false || true));
// traces false

your current if statement in english reads:
if song.position equals 1 or 2 or 3 go to and play 10.

is that what you mean?

Beta, I’ll try the or, but I don’t think it will work:rambo:

sbeener, Yes that is excactly what I want my if statement to say.
I am really trying to put an audio loop over another audio loop in time by rolling over a button and having the second loop start on beat 1,2,3 or 4 of the main loop.

What do you want me to do with the trace command?

What about the else if command to put the multible staments?

Just use different if statments instead of the ||, works great.

Thanks people:)

waffe, the traces were meant to illustrate how order of evaluation will change the results.

if that was what you wanted why not say:

sp = song.position;
if(sp > 0 && sp < 4) gotoAndPlay(10);

but if you have it working now probably best not to change it. ; )

Nice idea but lets say that “sp = 1” is the first beat of the song and “sp = 2” is the second beat of the song and so forth.

Lets say then when I click a button a new sound starts that fits in very well with the ongoing song when it starts on beat 1,2,3 or 4.

There for if I used
button_btn.onpress = function(){
if(sp > 0 && sp < 4){
sound2.play()
}
}

The new loop could start any time after I click the button except after beat 4. Most likely this would not sound right because the new loop did not start on beat 1,2,3 or 4.

Thus, I need more resolution in my “if statements” to dictate when my new sound can play.

New problem on this topic, if you would please look at thread “refresh rate = frames or ?”