Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


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)-> http://blog.bwhiting.co.uk/ <-
    as3 helper/shortcut lib (v1.2) -> http://code.google.com/p/bwhiting/downloads/list <-
    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 kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012