- Home /
Changing dynamic toggle.isOn in List
I'm pretty deep into this program. I have 4 columns of toggles dynamically created. The user selects one from each column. Those selections are saved into their own lists. The linking list is the roomTrackList. so on the next panel it lists the users choices loading from each List. They are tracked by sharing the index with the roomTrackList.
My problem: When switching back to the Choice Panel I want to select other choices, then select the room again and hit a load button. It then takes all the toggles in each column and resets them to the choices previously saved in each array.
I'm currently trying to compare the text of the toggles to the text in the array then take the toggle component and switching the isOn. It errors on me error CS0029: Cannot implicitly convert type string' to
bool'
My code:
for (int i = 0; i < roomTrackList.Length; i++) {
// Check is Room is selected
if (roomTrackList[i].GetComponentInChildren<Toggle> ().isOn == true) {
// Check is RoomArray is = to the Room Selected
if (RoomArray[i] == roomTrackList[i].GetComponentInChildren<Text>().text)
{
Pet_Name.text = PetArray[i];
Owner_Name.text = OwnerArray[i];// need to set it equal to the one in the array.
for (int n = 0; n < techTrackList.Length; n++)
{
if (TechArray[i] = techTrackList[i].GetComponent<Text>().text)
techTrackList[i].GetComponent<Toggle>().isOn = true;
}
for (int n = 0; n < doctorTrackList.Length; n++)
{
if (DoctorArray[i] = techTrackList[i].GetComponent<Text>().text)
doctorTrackList[i].GetComponent<Toggle>().isOn = true;
}
for (int n = 0; n < statusTrackList.Length; n++)
{
if (StatusArray[i] = statusTrackList[i].GetComponent<Text>().text)
statusTrackList[i].GetComponent<Toggle>().isOn = true;
}
// Check is RoomArray is not equal to RoomTrackList text then
} else if(RoomArray[i] != roomTrackList[i].GetComponentInChildren<Text>().text)
{
foreach (GameObject temp in techTrackList)
{
if (TechArray[i] = techTrackList[i].GetComponent<Text>().text)
techTrackList[i].GetComponent<Toggle>().isOn = false;
}
foreach (GameObject temp in doctorTrackList)
{
if (DoctorArray[i] = techTrackList[i].GetComponent<Text>().text)
doctorTrackList[i].GetComponent<Toggle>().isOn = false;
}
foreach (GameObject temp in statusTrackList)
{
if (StatusArray[i] = statusTrackList[i].GetComponent<Text>().text)
statusTrackList[i].GetComponent<Toggle>().isOn = false;
}
//techTrackList[i].GetComponent<Toggle>().isOn = false;
//doctorTrackList[i].GetComponent<Toggle>().isOn = false;
//statusTrackList[i].GetComponent<Toggle>().isOn = false;
}
Im at a loss of any other way to do it. Any help would be appreciated.
Link to a screenshot to get an idea of what I'm trying to do.link text
You need to post the line that's throwing the error. From the image you posted it's 302, but you're posting from the middle of your file, so I can't tell which one it is.
you need to use == ins$$anonymous$$d of = in all the if statements.Hope it works :)
Oh man. Thank you. After 10 hours I was just too close to it and fatigued to see it. It's the old VB coding that's confusing me. Thank you for pointing out that and thankfully it was that easy.
Your answer
![](https://koobas.hobune.stream/wayback/20220613195136im_/https://answers.unity.com/themes/thub/images/avi.jpg)