Hi! I have a group of collider objects in my project that ‘pop up’ a message when the player touch them (using OnTriggerEnter). The messages are taken from a SQLite database. The messages are classified by categories and each collider object activates a specific type of message. I’m thinking on ‘activate’ each message using a different sets of bools with a ‘if’ statement, but if I need to copy all the query inside every ‘if’, including the readers and other stuff, the code is going to be excessively long, because I have 15 categories, so, 15 if statements. This is the code:
private void Insert()
{
using (IDbConnection dbconn = new SqliteConnection(conn))
{
dbconn.Open();
using (IDbCommand dbcmd = dbconn.CreateCommand())
{
if (mastin== true)
{
string sqlQuery = "SELECT * FROM Animals WHERE Breed= 'Mastin'";
dbcmd.CommandText = sqlQuery;
using (IDataReader reader = dbcmd.ExecuteReader())
{
while (reader.Read())
{
int id = reader.GetInt32(0);
string category= reader.GetString(1);
string dialog= reader.GetString(2);
string A = reader.GetString(3);
string B = reader.GetString(4);
string C = reader.GetString(5);
string D = reader.GetString(6);
DogText.text = dialog;
AnswerAText.text = A;
AnswerBText.text = B;
AnswerCText.text = C;
AnswerDText.text = D;
}
reader.Close();
dbcmd.Dispose();
dbconn.Close();
}
}
}
}
My Question is: there is some way to manipulate the ‘if’ without be obligated to make a lot of them and copy the contents of it again and again. I mean, something that changes the query depending of what condition of ‘if’ has been activated. eg. If the statement was activated by the bool “dog”, a proper word of the query changes to “dog” too. Something like that exists? Thanks in advance.