Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6630315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:23:08+00:00 2026-05-25T22:23:08+00:00

Let’s say that we build a game and we have a player character. That

  • 0

Let’s say that we build a game and we have a player character. That character in the game will do many actions, like walking, jumping,attacking, searching target etc :

public class Player extends MovieClip
{
   public function Player(){}
   private function walk(){}
   private function attack(){}
   private function jumping(){}
   ...
   ..
   .
  private function update(){}
}

Now, for every state or action we want to execute a different code. Now, how to do this? I can think of 3 ways.

1.With events – as I understand, event system is costly to use, so I’ll skip this one.
2. With simple checks in the update() – something like if(currentStateAction) {doSomethingHere} or with switch statement. But what if the actions are not mutually exclusive, e.g. it can jump and attack in the same time? Than we have to use if() for every action, e.g. to do checks for every frame.
3. I came up with this solution on my own and I need to know is this better than option number 2:

//declare Dictionary. Here we will add all the things that needs to be done
public var thingsToDo:Dictionary = new Dictionary(true);

//in the update function we check every element of the dictionary
private funciton update():void
{
  for each(item:Function in thingsToDo)
  {
    item.call();
  }
}

Now, every time we need to do something, we add a element, like thingsToDo[attack]=attack;
Or if we don’t want to do something anymore: delete thingsToDo[attack];

In this … system … you don’t need to check every frame what the object should do, but instead, you only check when is needed. It’s like a event driving system. Say for example, the object don’t need to check for attack until new enemy is spawn. So. when spawing a new enemy, you will add thingsToDo[attack] = attack; and etc.

So the question: Is this faster than option number 3? Any idea how to do this checking differently?
Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:23:09+00:00Added an answer on May 25, 2026 at 10:23 pm

    You should probably focus on making it work the way you want (flexible, easy to maintain and modify), instead of making it as fast as possible. This is very unlikely to ever be a real bottleneck.

    Premature optimization is the root of all evil, and all that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I have a set of relations that looks like this: relations
Let's say you have a method that expects a numerical value as an argument.
Let's say I have a bunch of links that share a click event: <a
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say I have multiple requirements for a password. The first is that the
Let's say that I have a date in R and it's formatted as follows.
Let's say you have a class library project that has any number of supplemental
Let's say I have an abstract parent class called shape, and that there are
Let's say I have table with column 'URL' whrere I store urls like this
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.