Hi, all! This would spare me a HUGE amount of time if this is possible…

Is there any way I can add a prefix to a variable? In my game, I have 3 save slots, and a different variable set for each, and a static int in a master script that holds the current and active slot number. For instance:
If I make a variable ‘apple’, I’d have to make it for all 3 slots, which is fine by me. So, in a script labeled ‘Master’, there would be:

static var S1_apple : int;
static var S2_apple : int;
static var S3_apple : int;

Which is great. But if I want to modify it in another script, I have to do this:

var value = 23;

function Start(){
    if(Master.CurrentSlot == 1){
        S1_apple = value;
    }
    if(Master.CurrentSlot == 2){
        S2_apple = value;
    }
    if(Master.CurrentSlot == 3){
        S3_apple = value;
    }else{
        Debug.Log("You forgot a slot!");
    }

}

For EVERY VARIABLE which takes forever and a half. So my question is this:

Can I add prefixes to variable names? At the beginning of the script, I would get the CurrentSlot in the Start() function, and then assign either S1_, S2_, or S3_ to a variable depending on the slot. Then, when I want to modify a variable, I could just use the prefix variable like

*prefix variable* + apple = value;

Look how much code that saved! 0_o
But obviously that doesn’t work.

Is there a way to do this? You’d be my saviour! :smiley:

Thanks!- YA

How about an array? Are you sure you need those variables to be static? Anyway…

static var apple : int[] = new int[3]; // array with 3 elements

var value = 23;

function Start()
{
    // array indices start at 0 not 1
    var index = Master.CurrentSlot-1;
    if(index >= 0 && index < apple.Length)
        apple[index] = value;
}