variable looking for array content, array looking for another array...
it's been a while since i posted something here... but i'm having a little trouble with that, can someone put me in the correct way? thanks ^^
here we go, how can i tell a variable to "record" the content of an array? the array must be safe of course. here's what i have:
Code:
array_n = ["a", "b", "c", "d", "e"];
check1 = array_n[0]+array_n[1]+array_n[2];
trace(check1);
^ this works fine! the trace action give me abc. BUT:
Code:
for (i=0; i<=2; i++) {
check1 = array_n[ i ];
}
trace(check1);
^ here, the trace action give me only c. it's normal, ok. but how can i keep the for loop and having again abc as a result?
another problem/question
here, the idea is quite the same, but it doesn't work as i want either
Code:
combo_array = new Array();
combo_array[0] = ["down", "forward", "forward"];
combo_array[1] = ["down", "down", "forward", "forward"];
combo_array[2] = ["down", "backward"];
combo_array[3] = ["down", "down"];
//
combo_actual = ["down", "forward", "forward"];
> now i'm writing a for loop; i just want to check if one of the combo_array is similar to the combo_actual one:
Code:
trace(combo_actual);
for (i=1; i<=combo_array.length; i++) {
trace(combo_array[i-1]);
if (combo_array[i-1] == combo_actual) {
trace("working!");
}
}
here are the results with the trace actions:
trace(combo_actual)
> down,forward,forward
trace(combo_array[i-1])
> down,forward,forward
> down,down,forward,forward
> down,backward
> down,down
as you can see, there is a similarity (down,forward,forward), but the "working!" never appears. am i missing something?
thanks for your help ^^
Re: variable looking for array content, array looking for another array...
why don“t you store the index of the combo instead of the whole combo array:
actual_combo = 2;
Code:
combo_array = new Array();
combo_array[0] = ["down", "forward", "forward"];
combo_array[1] = ["down", "down", "forward", "forward"];
combo_array[2] = ["down", "backward"];
combo_array[3] = ["down", "down"];
//
combo_actual = 2;
trace(combo_actual);
for (i in combo_array) {
if (i == combo_actual) {
trace("working!");
}
}
just an idea,
k. ;)