The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 4 of 4

Thread: Split big functions?

  1. #1

    Split big functions?

    Is there a limit for how many statements I should put in the same function? I have a function that takes care of all of the code for a movieclip and it's up in 16 "if statements" allready, should i split it up in more functions or not? I'm a novice, and never coded anything big so it might not even be that many, i don't know

  2. #2
    Registered abUser
    could probably have hundreds dare I say thousands...not exactly manageable though.

    there is usually a better way to handle things if its getting more complex than a few if statements
    blog (experiments and code)-> <-
    as3 helper/shortcut lib (v1.2) -> <-
    agal helper -> Clicky here <- UPDATED

  3. #3
    It's not much, unless the Class with this function is instantiated thousand of times (e.g. it's a particle). Then You could consider dividing the function to parts executed in different frames, or optimizing the code.

    You should care more about loops, like for (var i:int = 0; i<10000; i++) { doSomething() }
    (I wish to develop my English, feel invited to correct me.)

  4. #4
    Thank you for the replays

    the function is instantiated twice so i guess it should be ok. You are right, i should learn to use loops, though i don't think it would be useful for this particular thing. I'm making a game similar to bomberman, and that function handles the controls for both players.

    It's a tilebased game that works like this ( not sure if it's the best solution, but it's what i could work out, appreciate feedback and tips )

    When you hit a directional key a walk animation will play that moves the player a certain distance in that direction. Afterwards the player is reset to the "idle" animation (moved back to it's original position) and pixles are added to the x/y position so it looks like you walked a tile and then stopped. Theres a if statement for each directional key, and one for resetting the player to the idle stance when he reaches a certain frame. ( 8 statements * 2 players)

    If there is any way to optimize this that you want to share with me i would be very grateful

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012