So I made a custom class and added several variables to it. My goals is to add all these new variables into a array called ‘allDialogs’
class DialogBalloon {
var id : int;
var nextId = new Array(); //next dialog line to go to
var actor : Transform;
var listener : Transform;
var title : String;
var text : String;
var isPlayerQuestion : boolean; //If its a Question that the player can ask(needs to be unlocked to show)
var isStatement : boolean; //just a statement with no answer.
var isUnlocked : boolean; //once unlocked the player can use it as option.
var wasDisplayed : boolean; //if it has already been said
}
var currentDialogDisplay : DialogBalloon;
var welcomeHome00 : DialogBalloon = new DialogBalloon();
var welcomeHome01 : DialogBalloon = new DialogBalloon();
var welcomeHome02 : DialogBalloon = new DialogBalloon();
var welcomeHome03 : DialogBalloon = new DialogBalloon();
var traffic01 : DialogBalloon = new DialogBalloon();
var traffic02 : DialogBalloon = new DialogBalloon();
var dinner01 : DialogBalloon = new DialogBalloon();
var dinner02 : DialogBalloon = new DialogBalloon();
var herDayA01 : DialogBalloon = new DialogBalloon();
var herDayA02 : DialogBalloon = new DialogBalloon();
var herDayB01 : DialogBalloon = new DialogBalloon();
var herDayB02 : DialogBalloon = new DialogBalloon();
var phoneA01 : DialogBalloon = new DialogBalloon();
var phoneA02 : DialogBalloon = new DialogBalloon();
var phoneB01 : DialogBalloon = new DialogBalloon();
var phoneB02 : DialogBalloon = new DialogBalloon();
var allDialogs = new Array(); //Array that contains all the game dialogs
So under Start() I tried to add these to the Array.I found that if I do the long way it works well:
allDialogs.Add(welcomeHome00);
allDialogs.Add(welcomeHome01);
allDialogs.Add(welcomeHome02);
allDialogs.Add(dinner01);
allDialogs.Add(traffic01);
But I would like to get something that is automatic, this is what I tried to write but it just doesn’t work…
for (var DialogBalloon in Dialog_Manager){
allDialogs.Add(DialogBalloon);
}
Is it possible to build a loop that will include all these new variables?
Hope the question was formulated in a clear way.
Thanks in advance!
//SMALL UPDATE//
I forgot to add, all these are being written in a script called ‘Dialog_Manager’, that is the reason why I added it to the for loop.
And also all these variables have actual values that are declared in the Start() function, here are some of them:
//WelcomeHome
welcomeHome00.id = 1;
welcomeHome00.nextId.Add(welcomeHome01);
welcomeHome00.nextId.Add(welcomeHome02);
welcomeHome00.nextId.Add(welcomeHome03);
welcomeHome00.actor = objManager.actorWife;
welcomeHome00.listener = objManager.actorPlayer;
welcomeHome00.text = "How did your day go?";
welcomeHome01.id = 2;
welcomeHome01.title = "Ok";
welcomeHome01.actor = objManager.actorPlayer;
welcomeHome01.listener = objManager.actorWife;
welcomeHome01.text = "It was ok.";