# Any way to reference functions by number?

**URL:** <https://forum.kirupa.com/t/any-way-to-reference-functions-by-number/249666>\
**Category:** Uncategorized\
**Created:** [January 21, 2008, 4:45pm UTC](https://forum.kirupa.com/t/any-way-to-reference-functions-by-number/249666 "2008-01-21T16:45:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![oldmanwinter](https://avatars.discourse-cdn.com/v4/letter/o/b38774/32.png) [@oldmanwinter](https://forum.kirupa.com/u/oldmanwinter)\
**Post date:** [January 21, 2008, 4:45pm UTC](https://forum.kirupa.com/t/any-way-to-reference-functions-by-number/249666/1 "2008-01-21T16:45:48Z")

</div>

in this game i’m working on, i’ve been tweaking my code and i’ve realized that i could simplify my code in a couple of areas if i could just assign functions numbers and have them called based off of a variable. here’s an example of code which could be simplified: for my enemy AI, i have four functions and i want one of them to run, depending on the value of a variable

```auto
if(ai_int<3)
{
     if(ai_int==1)
     {
          run_left();
     }
     else
     {
          run_right();
     }
}
else
{
     if(ai_int==3)
     {
          attack();
     }
     else
     {
          jump();
      }
}

```

instead of doing all those checks, it’d be a lot simpler if i could number my functions (run\_left would be 1, attack would be 3, etc) and replace the above code with something simple like " run function(ai\_int) ". is there any way to do something like this? sorry if this is a real noob question, TIA
