- Home /
Loading asset depending on variable's value
I want to do some kind of pokemon game, but I got a little problem. Every "pokemon's " stats are in separate csv file and I would like to know if there's a way to load a specific asset depending on variable's value without putting in like 150 "if"s?
Comment
Best Answer
Answer by Zodiarc · Jul 09, 2018 at 01:30 PM
Adapt a naming scheme, a directory where all the csv files are and use that.
For example (using pokemon):
data/stats/bulbasaur.csv
data/stats/ivysaur.csv
data/stats/venusaur.csv
In your game you load the stats by using the current pokemon name:
final string baseDirectory = "data/stats/";
string filename = currentPokemon.name.ToLower() + ".csv";
// load using baseDirectory + filename
That way if your pokemon name is Ivysaur it will result to
"data/stats/ivysaur.csv"