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. Dismiss Notice

Relational Arrays

Discussion in 'Scripting' started by Gilead7, May 31, 2009.

  1. Gilead7

    Gilead7

    Joined:
    Apr 2, 2009
    Posts:
    27
    I've been thinking about my "player script."
    It will have to keep track of several things each one an array onto itself.

    Statistics, Player Condition, inventory, health of weapons, quest flags, etc.
    How can I keep them all easily organized as a group? Should I use a relational database is there some form of relational array?
    Any thoughts?
    Thanks!
     
  2. psychicparrot

    psychicparrot

    Joined:
    Dec 10, 2007
    Posts:
    884
    Not sure if this helps, but I figured I'd chime in ... personally, I would store them most game data in classes...

    For example, I'd have a class that dealt with just inventory items. The playercontroller could then call functions on it like 'addtoinventory' or 'drop' etc.

    You could have classes for your weapons, just simple classes consisting of a few variables like 'damage','power','type','name' or something then when an item is picked up, you actually add a reference to your class in the inventory array.

    Your player control script could end up getting really messy if you try to store all in the one, so I would try to separate them in specific classes.

    Good luck!
     
  3. zigs

    zigs

    Joined:
    May 27, 2009
    Posts:
    145
    Yes, so would I. It might not seem very productive at first, but it's far better in the long run.

    - Chris :)
     
  4. zelk

    zelk

    Joined:
    Mar 13, 2009
    Posts:
    246
    I agree. To make some relations easier to work with, you could make public variables in the classes so that you can relate the objects together... say you have these classes: Character and Item.

    The Character class could have one public variable called EquippedItems[] where you in the UnityGui can attach Items easily. That way, you can set up different player and enemy Prefabs using the editor.

    /Ricky
     
  5. Gilead7

    Gilead7

    Joined:
    Apr 2, 2009
    Posts:
    27
    I haven't seen anything to show how to save a game in progress. I'm guessing you have to import the IO functions from .net. Anyone have some code examples? If I'm using classes on the player, how exactly would I output that and once done, how to import it again to continue the fun?

    Thanks!
     
  6. zelk

    zelk

    Joined:
    Mar 13, 2009
    Posts:
    246
    Saving state can be made using RPC-calls to the server and letting the server save the information to a database or some kind of data files. I strongly recommend using a real database.