dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: storing x & y location in an array

  1. #1
    Senior Member
    Join Date
    Sep 2002
    Posts
    138

    storing x & y location in an array

    I am working on a turn-based space ship combat game and I am trying to store the x & y coordinates of my ship's movement in an array. I have included it below and in a sample fla I am using. The trace command always spits back 'undefined' and it is driving me crazy. If someone could help me (and help explain what went wrong) I would appreciate it.

    onClipEvent (load) {
    var shipMovesx = new Array();
    var shipMovesy = new Array();
    shipMovesx.length = 2;
    shipMovesy.length = 2;
    }

    onClipEvent (keyDown) {
    if (Key.isDown(Key.UP)) {
    _root.ship._y -=10;
    var smx = getProperty(_root.ship, _x);
    var smy = getProperty(_root.ship, _y);
    shipMovex.push("smx");
    shipMovey.push("smy");
    trace (shipMovex());
    trace (shipMovey());

    }
    }

  2. #2
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    change the code to;
    Code:
    onClipEvent (load) {
    var shipMovesx = new Array();
    var shipMovesy = new Array();
    }
    
    onClipEvent (keyDown) {
    if (Key.isDown(Key.UP)) { 
    _root.ship._y -=10;
    var smx = getProperty(_root.ship, _x); 
    var smy = getProperty(_root.ship, _y);
    shipMovex.push(smx);
    shipMovey.push(smy);
    trace (shipMovex); // dumps the entire array
    trace (shipMovey); // dumpd the entire array
    }
    }
    if you wanted to simplify things a little you could use one array of objects;
    Code:
    onClipEvent (load) {
    var shipMove = new Array();
    }
    
    onClipEvent (keyDown) {
    var i;
    if (Key.isDown(Key.UP)) { 
    _root.ship._y -=10;
    shipMove.push({x: _root.ship._x, y: _root.ship._y});
    // dump
    for(i=0;i<shipMove.length;i++)
    	trace(shipMove[i].x+","+shipMove[i].y);
    }
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  3. #3
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    I made this the other day, could be usefull to someone... (Similair topic thats all)
    Last edited by random10122; 04-08-2008 at 07:35 PM.

    fracture2 - the sequel
    fracture - retro shooter
    blog - games, design and the rest

    "2D is a format, not a limitation" -Luis Barriga

  4. #4
    Senior Member
    Join Date
    Sep 2002
    Posts
    138
    Thanks BlinkOK, you were a real help! Your first code snippet didn't work, but your second did the job. Any idea why it didn't work?

    random10122
    Thanks! Hopefully this thread will help someone else. I am going to take your code apart.

  5. #5
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    yeah! because i defined the arrays as shipMovesx and shipMovesy and then i changed shipMovex and shipMovey (No 's'). silly drongo i am!
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  6. #6
    Senior Member
    Join Date
    Sep 2002
    Posts
    138
    An Aussie/New Zealander, excellent! Hello from across the pond!

    Sorry, should have seen that. Thanks, I have always been afraid of arrays and I finally need to learn how to use them so, of course, I am a spaz when it comes to that stuff. If I ever finish this damn engine I am making, you and Tonypa (and anyone else, of course) will receive a HUGE thanks in the credits.

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