I have a problem that I try to solve with NMinimize.

I have a scoring function, which will give me a final score. The problem has many variables, so instead of having them as parameters, they are assembled by variable name. Here is a simple example:

```
scoreResults = Function[
Module[{temp, i},
temp = 0;
Print["Checkpoint 0: " <> ToString[temp]];
For[i = 0, i < 2, i++,
temp = temp + ToExpression["aaa" <> ToString[i]];
If[ToExpression["aaa" <> ToString[i]] > 300,
temp = temp + 100000;
];
Print["Checkpoint 1: " <> ToString[Evaluate[temp]]];
];
Return[temp, Module];
]
];
```

Observe the If condition. Now, when I evaluate with a Replace all, I get the following:

```
scoreResults[] /. {aaa0 -> 123, aaa1 -> 456}
Checkpoint 0: 0
Checkpoint 1: aaa0
Checkpoint 1: aaa0 + aaa1
579
```

That is not right! I think what is happening is that the function is being evaluated before replacing everything. Is it possible to avoid this without having input parameters? My problem has many variables, and the scoring function will have many nested loops, so it is key to assemble variable names on the fly within the scoring function. Even if I use input parameters for the function, I find that my ToExpression ["aaa" <> ToString [i]] is not effective.

Ultimately, I would like to use this scoring function with NMinimize as such:

```
NMinimize[{scoreResults[], {aaa0 > 222, aaa1 > 333}}, {aaa0, aaa1}]
```

Currently the answer you give me is incorrect:

```
{555., {aaa0 -> 222., aaa1 -> 333.}}
```

Thanks in advance for your help, I have been trying to solve this for a while. I understand that when I get to the NMinimize part, I will probably have to use NumericQ, but for now, I just need to overcome the initial problem I have when getting the function to produce the correct value, including the If statement.