dcsimg
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: as3 game queue

  1. #1
    Senior Member Alluvian's Avatar
    Join Date
    Jun 2006
    Posts
    967

    as3 game queue

    In as2, I would often build an array of strings to work as a game queue. Using eval they could be executed in order. It was useful for handling animations that had to happen in the correct order, like having a tank move 2 north, then 3 east, then 1 south. Stuff like that.

    Is there a way this can be done in AS3?

  2. #2
    5+5=55 Schfifty Five's Avatar
    Join Date
    Jun 2006
    Posts
    698
    The data structures at polygonal.de have a Queue which you might find useful:

    http://lab.polygonal.de/ds/

    Each node can hold whatever data you want, so you could make it some sort of animation command.

    Or, you could download an animation library (i.e. Tweener: http://code.google.com/p/tweener/) which would be able to accomplish the same thing in a different way.

  3. #3
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,379
    Why can't you just use the same method from AS2?
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  4. #4
    Senior Member Alluvian's Avatar
    Join Date
    Jun 2006
    Posts
    967
    Imprisoned Pride,

    To my knowledge, there is no equivalence of eval() in AS3. A google search last night sent me to about 6 forum threads that concluded that eval no longer exists. Most of them said good riddance, but since my programs are usually chock full of eval and references to the root I am the model of a bad programmer I guess. I don't have anyone to teach me how to be a good one, heh.

  5. #5
    Developer dVyper's Avatar
    Join Date
    Oct 2008
    Location
    UK
    Posts
    168
    Perhaps instead of calling eval just call a function passing the value of the array element. That function can then use a break statement to do the relevant things depending on the parameter passed.

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You could create thunks* and put those in your queue. When it's time to execute one, just call it.

    *A thunk is a no-argument function which is used to delay processing. For instance, let's say you want to call move(2, Direction.NORTH) at some point in the future.
    Code:
    var aThunk:Function = function():void{
      move(2, Direction.NORTH);
    }
    queue.push(aThunk);
    //later...
    queue.shift()(); //get front of queue, execute it.
    I've created a utility that helps with this, as well as other Functional programming tasks
    http://cosmodro.me/blog/2008/aug/26/...ity-functions/

    You could use it like so:
    Code:
    var aThunk:Function = FunctionUtils.thunkify(move, 2, Direction.NORTH);
    queue.push(aThunk);
    //later...
    queue.shift()(); //get front of queue, execute it.

  7. #7
    Senior Member Alluvian's Avatar
    Join Date
    Jun 2006
    Posts
    967
    Quote Originally Posted by dVyper View Post
    Perhaps instead of calling eval just call a function passing the value of the array element. That function can then use a break statement to do the relevant things depending on the parameter passed.
    I don't understand what this means...


    The polygonal labs stuff was GREAT, but that was just an alternative to an array for the actual queue itself. Their example just stored waypoint data (x,y) coordinates....

    I would want to be able to execute methods like:

    player1.move(2,"west");
    player1.attack(mob4);
    mob4.die();

    I could store this stuff in an array of objects like:
    ({player1,'move',Array (2,"west")}, {player1,'attack', Array(mob4)}, {mob4,'die',Array()})

    So each object has the class instance, the method name, and the arglist in an array.

    The part I don't know if it is even possible, is how do I then EXECUTE that method on that instance of that class with those args? In AS2 I would do this with eval().

    Am I out of luck in AS3? I am at a loss on how to handle game flow without a way to do this... It is just how my brain is wired...
    Last edited by Alluvian; 05-28-2009 at 11:29 AM.

  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Was my post invisible, or just too high level?

    Using FunctionUtils (or you could roll your own, but it's already there), you could build your queue like this.
    Code:
    queue.push(FunctionUtils.thunkify(player1.move, 2, "west"));
    queue.push(FunctionUtils.thunkify(player1.attack, mob4));
    queue.push(FunctionUtils.thunkify(mob4.die));
    And you can execute things sequentially like this:
    Code:
    while (queue.length > 0){
      queue.shift()();
    }

  9. #9
    Senior Member Alluvian's Avatar
    Join Date
    Jun 2006
    Posts
    967
    Sorry, I saw it, but thought it would only work with functions and not methods of a given instance.

    In retrospect that is pretty stupid, since functions are all methods now, just of the main timeline MovieClip, right? I was just thinking the thunkify thing only worked locally within one object.

    The proper response would then be "THANKS! I'll try this when I get home!"

  10. #10
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Edit: just saw your response. Thanks.

    With your objects, you could also do this:
    Code:
    var o:Object = {obj:player1, method:'move', args:[2, 'west']};
    o.obj[o.method].apply(null, o.args);
    Last edited by 5TonsOfFlax; 05-28-2009 at 11:42 AM.

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