Question Update:
Hey all,
I’m writing the code for my savegames using Playerprefs, which only supports integers or floats.
I did see that there is a script on the community wiki that adds array support. But because I do not have hundreds of values to save I thought to stay with the supported integers.
So I have about 50 integers named:
Level001,
Level002,
Etc,
And instead of making huge if statement to set the integers I thought there had to be a way to “dynamically” type them.
So instead of:
If (Loadedlevel == 1)
{
Level001 = 1;
}
someway to combine the beginning of the variable name: Level with the loadedlevel
To get: Level001.
And be able to set that “combined variable” to a value.
I hope this clears up my question, my original question follows:
////
Original question:
////
Hey all,
I’m writing the code for my save games using PlayerPrefs, and as a result I have some integers that I need to set at the end of a level.
I’ve been looking for a way to combine a couple of strings so that I can access my integer variable without a lot of code.
something like:
["levelCompletedEasy001_" + theLevelNumber] = 1;
The above doesn’t work, but does anyone know of a way to do that properly?
The other way I could think of to solve my problem would be the following, which would result in a lot of lines of code…
function setLevelCompletion(level : int)
{
if (level == 1)
{
levelCompletedEasy001_001 = 1;
}
if (level == 2)
{
levelCompletedEasy002_002 = 1;
}
}
There has to be a more efficient way right?
Thanks a lot!