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
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