A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: variable looking for array content, array looking for another array...

  1. #1
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601

    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 ^^
    Last edited by marmotte; 06-15-2003 at 11:44 AM.

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    1.
    code:

    for (i=0; i<=2; i++) {
    check1 += array_n[ i ];
    }
    trace(check1);



    or to write it simpler:

    check1 = check1+array_n[ i ];

    2.
    Dont know better way, but you can use array.toString to compare arrays:
    code:

    for (i=1; i<=combo_array.length; i++) {
    trace (combo_array[i-1]);
    if (combo_array[i-1] .toString ()== combo_actual.toString ()) {
    trace ("working!");
    }
    }


  3. #3
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    thanks a lot. you are always so fast ^^

  4. #4
    w00t io::pred's Avatar
    Join Date
    Mar 2003
    Location
    Sydney, Australia
    Posts
    163
    bah.. beat me.

    1:

    check1 += array[i] is the faster way =)


    2:

    Instead you could use:

    combo_array[i-1].join() == combo_actual.join()

    Not sure which one is faster.


    You improving the fighting game againg marmotte?

  5. #5
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    thanks io : : pred
    You improving the fighting game againg marmotte?
    you guessed it ^^
    my combo system is finally satisfying for me... pheew, finally...
    yes i was planning to release a big update for this game. i have had my final exams during one month now, so i'll be free again in several days... maybe.

  6. #6
    Senior Member
    Join Date
    Apr 2001
    Location
    Candyland
    Posts
    423

    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.

  7. #7
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    hello kay

    well, if think your code will work that way, but that's not exactly what i was looking for... because the combo_actual array is the famous array that stores each key you press... so no way to look for its index since it can be a lot bigger or smaller...

    thanks for your help, but i think the combo system i have now is a lot more flexible than before ^^ maybe it can be shortened a little bit more, but basically it looks like this:

    1) i have an array that stores all your key presses (i rewrote that part, now you can even insert combos like forward + forward, which was impossible before, the array deleted automatically similar and continuous keys, in order to prevent the fact that you keep pushing left, and at the same time fill the array 1000 times with "left")

    2) i have another collection of arrays that stores all the character's combo abilities,. they look like the combo_array i posted. plus another complementary array designed to tell some details, like "how strong is the combo", "how impressive will be the impact", "how will it affect your strength", "what label will play the character" etc...

    btw, i just rewritten the horizontal scrolling code, it's a lot smaller than before... ^^

  8. #8
    Illuminatus! fospher.com's Avatar
    Join Date
    Jan 2002
    Location
    5th Dimension
    Posts
    2,185
    I see that you're back 'motte! I was wondering where the hell you were. I didnt read your post at all, I just dropped by to say hello. Hello!

  9. #9
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    hey hey, fospher ^^
    i had final final exams during one month. duh!

  10. #10
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    This might be complete rubbish compared to what you guys already have but I saw what is was about and wrote this in about 15 minutes, if it comes in useful at all?

    Code:
    // Add the current array to check for combos
    combArr = new Array();
    combArr = [];
    // Set this to keep the array as small as possible
    maxCombo = 5;
    // Initiate the list of combos as arrays
    combos = new Array();
    combos[0] = ['up', 'up', 'down', 'down'];
    combos[1] = ['up', 'down', 'up', 'up', 'left'];
    // get the array lenth of combos for the loops
    cl = combos.length;
    // Add key listener to catch the current key
    keyListener = new Object();
    keyListener.onKeyDown = function() {
    	if (Key.isDown(Key.UP)) {
    		pushValue('up');
    	} else if (Key.isDown(Key.DOWN)) {
    		pushValue('down');
    	} else if (Key.isDown(Key.LEFT)) {
    		pushValue('left');
    	} else if (Key.isDown(Key.RIGHT)) {
    		pushValue('right');
    	}
    };
    Key.addListener(keyListener);
    // Test the arrays
    function pushValue(value) {
    	if (combArr.length>maxCombo) {
    		combArr.shift(combArr[0]);
    		combArr.push(value);
    		b = combArr.toString();
    		for (var i=0; i<cl; i++) {
    			if (b.indexOf(combos[i])>-1) {
    				this["move"+i]();
    				combArr = [];
    				b = "";
    			}
    		}
    	} else {
    		combArr.push(value);
    		b = combArr.toString();
    		for (var i=0; i<cl; i++) {
    			if (b.indexOf(combos[i])>-1) {
    				this["move"+i]();
    				combArr = [];
    				b = "";
    			}
    		}
    	}
    }
    function move0() {
    	trace("Super punch");
    }
    function move1() {
    	trace("Doody kick");
    }
    RipX

  11. #11
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    thanks RipX.

    i didn't tried it for now, but how good does the part
    keyListener.onKeyDown = function() {} works? is it better than a simple onClipEvent (keyDown)?
    because with only the keyDown event, a combo like "down", "down+forward", "forward" does not work. i fixed that problem some time ago, but maybe your keyListener is better for that kind of things...

  12. #12
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    Yeah, I guess you could catch 2 keys using this so it would work ok. As for the other code It just needs the timer code adding to clear the array and string if too much time passes between keypresses - 'tis very simple though as you know!

    RipX

  13. #13
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    I guess you could catch 2 keys using this
    if i remember correctly, it was not the problem of having 2 keys pressed at the same time, but more a keyUp intervention problem.
    > while doing this with the keys: "down", "down+forward", "forward", the array never showed the last "forward", surely because a keyUp was involved at this time...

    and about your counter, of course i did add one... it just delete the first entry in the array each 22 frames (the game runs at 60fps)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center