[JS] Adding a scripts variable to a variable

Hey all! This might be a little confusing but I will try my best to explain.

I know you can add scripts to variables e.g.

var stats : ScriptName;

And then you assign it with either more code or in the inspector.

However, what I want is to assign a variable from ScriptName to a variable on another script.

For example if Script1 had a variable named ElfStats.

Instead of adding

var stats : Script1;

Which gets the script, I want to get the ElfStats variable by assigning it in the inspector.

I don’t want to use stats.ElfStats because my plan is to have one main script which stores all the data about every character in their own variable. For example on Script1 there will be:

var character : String[] = ["Player", "5", "6"];
var elf : String[] = ["Elf", "3", "2"];
var demon : String[] = ["Demon", "6", "8"];
var ork : String[] = ["Ork", "1", "10"];

And then on each character I will assign Script2 there will be:

var stats : ScriptWithVariable;

Which then can be accessed from Script2:

rigidbody.AddForce(transform.forward * stats[5]); 
//It will be just stats, because the stats variable will contain the other variable.

This way, when you are programming a characters stats, you only need one script, so you are not looking through many and each one find its corresponding variable.

So you are literally assigning a variable from another script, as a variable.

I really hope you understand me and maybe can help me! Thank you all :slight_smile:

If i understand, the goal is to store all your characters stats in one script.
So why don’t you put a same tag on your elfs for example and do GetComponent(script). You will get the script variable and you will be able to get each stats of each character.
Then store it in a two dimension array ?