Returning a struct to another script

Hey, I am working on a game, and I need to record some stats of an enemy, so that I can copy them and apply them to another enemy later.

So I call the struct function with this line in script A:

targetStats.getStats();

which uses this code from script B:

public struct statLine
{
    public string name;
    public int lvl;
    public int hp;
    public int atk;
    public int def;
    public int spd;
    public int spcl;
}

public statLine getStats()
{

    statLine stat = new statLine();

    stat.name = myName;
    stat.idnum = ID;
    stat.lvl = level;
    stat.hp = health;
    stat.atk = attack;
    stat.def = defense;
    stat.spd = speed;
    stat.spcl = special;


    return stat;
}

How can I use this data in script A? I’ve tried making an identical struct and doing this:

recordStats stat = new recordStats();

stat = targetStats.getStats();

 public struct statLine
    {
        public string name;
        public int lvl;
        public int hp;
        public int atk;
        public int def;
        public int spd;
        public int spcl;
    }

I’ve tried playing around with passing parameters as well, and I’m out of ideas, short of using a separate function for each stat instead of a struct.

Any suggestions?

Thanks

Because they’re created in different scripts, they’re counted as different structs even if they have the same definition. You can however create a variable in one script that uses the struct from another script. For instance you can do this in Script A:

ScriptB.statLine stat = new ScriptB.statLine(); //References the struct through the Class
stat = targetStats.getStats();

While I think you can create an overload of the assignment operator to allow converting one struct to another, it’d be best if they were the same, as shown above. This way if you make a change to the struct in one script, you don’t have to remember to make the same change in the other.