• Echo Dot@feddit.uk
    link
    fedilink
    English
    arrow-up
    17
    ·
    2 days ago

    I’ve read from a few people who’ve done similar sorts of things that the solution to this problem is to just have everything track everything to begin with. Hunger level, heart rate, mood, everything you can possibly think of to track, and then just have everything else inherit from that global class. A lot of the values will be zero for some objects, but that’s okay, after all a storage crate doesn’t need a mood, both at some point in the future maybe you want to add an emotional box, and your code will definitely handle it now. Otherwise you have to go back in and alter everything every time you make a slight change.

    • rhombus@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      9
      ·
      1 day ago

      A more complicated but ultimately faster approach is using a structure like an Entity Component System. You build an entity (deer, person, plant) out of components that are just data (health, hunger, mood), and then each type of component has a corresponding system that updates all the components at once based on other values. It’s somewhat similar, but you save space on unnecessary components not being added, and it packs the data together in way that is faster for the computer to iterate through.