Hello there, fellow devs:
I’ve been recently planning a project for the past few days, for my high school biology class. Today, I finally tried to start it, but I’m having trouble figuring out how to execute it. In short, I am trying to code a creature with different types of behavior patterns and actions, as my goal is to create an ecosystem simulation. I am currently trying to figure out how to make different behaviors work, and it’s giving me quite the trouble.
Here’s an example of one of my issues: I want an “important” action, such as fleeing from predators, to be triggered as soon as the predator enters the creature’s line of sight. I know how to check when this happens, but what about cancelling any other actions the creature is performing? In order to flee from a predator, it has to drop whatever it is currently doing in order to flee and save itself, but how do I cancel any ongoing action in order for the creature to flee the predator? And what about making the creature go back to its normal routine as soon as it’s out of danger? There’s a lot to consider.
I’ve thought about storing different behaviors in functions and then breaking/running the functions when needed, but I don’t know how to break a function with another function or loop, let alone whether it’s even possible. I’ve thought about other methods, but none of them seem to work the way I need them to, I’m always hitting dead ends. I am also a bit unsure on how to go about making the creature revert back to its normal routine after finishing a specific action, although I can probably figure it out if I manage to do the first part.
I’m having a lot of issues with all of this, and I’ll be glad to listen to your ideas. Any help?