Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Solution for a ton of global constants? (monster stats, etc.)

Discussion in 'Scripting' started by Thaao, Dec 29, 2019.

  1. Thaao

    Thaao

    Joined:
    Jun 9, 2014
    Posts:
    54
    I'm working on an RPG game where I will have a large library of monsters that will have static global constant values (base stats, etc). I want to be able to easily add/remove or edit monsters from a read-only 'database' of them as I create more content for the game. I have an enum of monster 'species' and want to be able to add one to the enum and then have a place where I can enter all the static data that can be looked up at any time during the game through the enum reference.

    What is a good way to do this? Should I just use a text file formatted in a certain way and read from it whenever monster data is needed, or is there a better way?
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    Why do you want to save these things in a textfile or database? What speaks against having a classic class hierarchie where fields and methods are derived from base types? Like, all Monsters will have health and so on. All Wolfes are Monsters, but may have higher movement speed. By deriving and overriding, the amount of new stats you need to consider should be a lot lower. Very specific data can then either be directly added to the final monster type, or if used in more than one place, through an interface.

    I never worked on a game with hundreds of different enemies, and i know the classic approach can cause pretty large files, but i'd imagine the approach you intend to get a bit messy as well.
     
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,584
    Speaking purely from DB point of view and for single player, I would consider using sqlite, to organize data.

    Something alike WoW DB.
     
  4. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Not going into the particulars, I found that practical way to do this is using dictionaries, and then use JSON to read/write them. That way you can separate monster creation (write a small app to create the moster definition) and usage (the game that reads the monster definitions). In-between, you can use a text-editor to edit the monster stats after they have been written to file, since JSON usually writes text files.
     
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,021
    JSON kinda sucks for human editing though, Something simpler would be better I think.
     
  6. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Probably. Do you have a better recommendation'
     
  7. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,584
    Database, XML, maybe scriptable objects, Json, or any text frmat is not bad, but if you want edit data in bulk, then it can ecome difficult and tedious.

    DB,like SQL /Sqlite, and XML, allows to use tools, for mass searching, filtering and editing multiple entries at once.

    Wit XML is easy to implement some algorithms, I.e. Using Excel.
     
    csofranz likes this.
  8. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Actually, that's one hell of a good approach that I keep forgetting. If you have Excel (or open office), you can globally search/replace your data files (assuming you formatted them appropriately) if you can't (or are a lazy bum like me) grep.

    -ch
     
  9. Thaao

    Thaao

    Joined:
    Jun 9, 2014
    Posts:
    54
    XML with some help from Excel seems like the way I'll probably go. Thanks everyone for the suggestions~