My unit has been separated in 2 different types of “actions” the Move action and “Other” actions, they use different points and are independent of eachother, in this case how should i go about testing if the player has action points to do either a move action or an other action in the EnemyAI script, TryTakeEnemyAIAction.
I have two functions for checking if the unit has enough points to either move or to do other actions(naming will change most likely)
So apologies for the stupid question, I was quite tired at the time of posting it but i did figure out the solution to it… il leave the code snippet here in case anybody is doing something similar to what i am and might find this usefull.
Il just paste the check, the rest of the code is exactly the same as in the video.
I would caution you against using strings to identify the action, strings are very brittle and error prone, you should never use them for identifying things. I actually talked about this topic in a very recent video https://youtu.be/0_UiF-4-7xM?t=348
You could instead ask the enemyUnit to give you the MoveAction reference, assign the MoveAction in a separate field, then just compare baseAction == moveAction;
Nice job on implementing separate Move and Action points!
Hello there my favorite CodeMonkey!
Il take this time to thank you for all the hard work and all the knowledge you have shared with the community across the years, i have been following you for a long time and its a pleasure doing this course, i plan on releasing a game on steam and il use this course as a base to build upon, so thank you and keep up the good work.
Now on the topic at hand, you are absolutely correct and i have made the necessary changes to avoid using strings, i will place the code here in case anybody else needs it.
Also in the future i might want to make certain abilities(actions) use both a movement point and an action point so the if statements might need to check for something else instead of just the action, maybe a 2 bool flags, but thats for future me.
A small optimization here, as repeated access to a method that will yield the same result every time is unneccessary…
At the beginning of TryTakeEnemyAIAction:
if(baseAction == moveAction)
{
if (!enemyUnit.CanSpendActionPointsToMoveAction(baseAction))
{
continue;
}
}
//At this point, baseAction cannot == the moveAction, as
//that case has already be dealt with in the if clause that this else refers to
//making this if redundant.
else //if(baseAction != enemyUnit.GetMoveAction())
{
if (!enemyUnit.CanSpendActionPointsToTakeOtherActions(baseAction))
{
continue;
}
}