Issue with Built-in array using multiple types.

I’m following a guide as well as looking up multiple answers but I can’t find what exactly is wrong with my code though I assume it is relatively simple and I’m just ignorant (haven’t really learned C#).

I cannot figure why exactly my code is producing this error.

using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
public class GuardianStats {
        public class Guardians{
                public string name;
                public int guardID;
                public int startLevel;
                public int MaxLevel;
                public int Vit;
                public int MaxVit;
                public int Con;
                public int MaxCon;
                public int Pow;
                public int MaxPow;
                public int Mnd;
                public int MaxMnd;
                public int Def;
                public int MaxDef;
                public int Spd;
                public int MaxSpd;
        }
                Guardians[] guardianList = new Guardians[12];
                guardianList[0] = ("Cloudy Panther", 001, 1, 24, 25, 109, 22, 98, 16, 87, 32, 151, 23, 100, 32, 153);  //The line I get the error
}
//CS1519; Unexpected symbol '=' in class, struct, or interface member declaration

For some reference I’m making a monster collecting game and they’re formally called guardians. I’m trying to create an array that keeps track of all my monsters and their name, stats, portrait, abilities, and typing. I need to be able to call the base stats and make a new copy that the local player has that can level up and have varying stats from the base stat.

If I’m going to the complete wrong way with my idea of using an array, it would be nice to know of a better method.

You could try two things.
I’m not sure about the error, but it could be because of the way you tried to assign it to the array? Not sure if you can just use brackets like that, but someone can correct me about that.

You could try making a constructor for your Guardians class, then use that to create objects of monsters? Storing them as objects.
That would look like this:

public class GuardianStats : MonoBehaviour {

public class Guardians {

public string name;
public int guardID;
public int startLevel;

public Guardians(string_name, int_guardID, int_startLevel)
{
name = _name;
guardID = _guardID;
startLevel = _startLevel;
}

Guardians[] guardianList = newGuardians[12];

void Awake()
{

guardianList [0] = new Guardians ("Cloudy", 001, 1);

}

}

or you could just assign it like this and have it work the way you were doing it

public class GuardianStats : MonoBehaviour {

public class Guardians {

public string name;
public int guardID;
public int startLevel;

}

Guardians[] guardianList = newGuardians[12];

void Awake()
{

guardianList [0].name = "Cloudy Panther";
guardianList [0].guardID = 001;
guardianList [0].startLevel = 1;

}

}

I’d recommend the first one cause you can do cool things with constructors.
Hope that helps!

I can’t quite get your first code to work, the closest thing is changing:
public Guardians(string_name, int_guardID, int_startLevel)
to
public Guardians(string _name, int _guardID, int _startLevel)
but I still get errors. I did manage to get the second one to work and managed to use it in a makeshift status screen so that makes me happy, thanks. However you brought up cool things with constructors. What interesting things can you do with constructors that you can’t do with the second method you posted?

It looks like I forgot to close the Guardians class before this line -
Guardians[ ] guardianList = newGuardians[12];

Other than that it should work, if not let me know.

I think it would be wrong of me to say you can’t do it with the second method sorry, but constructors are really handy in that when ever you create a new object its constructor is ran, and inside the constructor function you can have something that says, ok, create this monster with random parameters, then instantiate it in the world.

E.g. pseudo code

public class monster {

public monster(string _name, int _id)
{
name = _name;
id = _id;
health = random number between (70, 100);
Instantiate game object in scene
}

void Update()
{
Run around and do what monsters do
}

}

Per that example, each time you want to create a monster you could just call monster new_monster = new monster(); and it would create a monster with some unique parameters and some set parameters and go about it’s business.

I’m not sure how/what your game does with Guardians, so it might not be a suitable method. But it’s something to look at. Object oriented programming is super handy

Constructors also have the ability to initialise private fields. This is useful for proper encapsulation. You hardly want something like maxLevel to have a public setter.