Type does not contain definition for "CurrentBool"... how come?

How come “CurrentBool” is not defined? And how can I define it to allow me to use it in the way I’m trying to use it in this script?

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using UnityEngine.EventSystems;

public class SearchEngine : MonoBehaviour {
    public Toggle[] Togs; //saves all the Toggle checkboxes as a Toggles array
    public GameObject[] AllObjects;
    List<GameObject> ShownObjects = new List<GameObject>();
    public GameObject instance;
    public GameObject[] DestroyedGOS;
    private bool CurrentBool;
    private int x;
   

    void RunList () {
        DestroyedGOS = GameObject.FindGameObjectsWithTag("model"); // destroys all models on screen to avoid duplicates
        if (DestroyedGOS.Length > 0)
        {
            foreach (GameObject GOdestroy in DestroyedGOS)
            {
                Destroy (GOdestroy);
            }
        }
        if (Togs [x].isOn == true) { //if the checkbox is marked, add models to list List
            foreach (GameObject go in AllObjects) {
                if (go.GetComponent<ModelProperties> ().CurrentBool == true && ShownObjects.Contains (go) == false) {
                    ShownObjects.Add (go);
                }

            }
        } else if (Togs [x].isOn == false) {
            foreach (GameObject go in AllObjects) {
                if (go.GetComponent<ModelProperties> ().CurrentBool == true && ShownObjects.Contains (go) == true) {
                    ShownObjects.Remove (go);
                }
                   
            }
        }
        foreach (GameObject ShownOneObject in ShownObjects) {
            var instance = (GameObject)Instantiate (ShownOneObject, ShownOneObject.transform.position, Quaternion.identity);
            Debug.Log (ShownOneObject);
        }
    }


        void WithSupport ()
    {
        CurrentBool = WithSupport;
        x = 0;
        RunList ();
    }

        void WithoutSupport () {
        CurrentBool = WithoutSupport;
        x = 1;
        RunList ();

        }

        void ResolutionModels () {
        CurrentBool = ResolutionModels;
        x = 2;
        RunList ();

        }
    }

Can you post the “ModelProperties” and the exact error message you get? As I can only guess now that “ModelProperties” does not have any (public) definition of “CurrentBool”.

ModelProperties:

using UnityEngine;
using System.Collections;

public class ModelProperties : MonoBehaviour {
    public bool WithSupport;
    public bool WithoutSupport;
    public bool ResolutionModel;
}

Assets/Scripts/SearchEngine.cs(28,73): error CS1061: Type ModelProperties' does not contain a definition for CurrentBool’ and no extension method CurrentBool' of type ModelProperties’ could be found (are you missing a using directive or an assembly reference?)

Assets/Scripts/SearchEngine.cs(35,73): error CS1061: Type ModelProperties' does not contain a definition for CurrentBool’ and no extension method CurrentBool' of type ModelProperties’ could be found (are you missing a using directive or an assembly reference?)

Assets/Scripts/SearchEngine.cs(50,17): error CS0428: Cannot convert method group WithSupport' to non-delegate type bool’. Consider using parentheses to invoke the method

Assets/Scripts/SearchEngine.cs(56,17): error CS0428: Cannot convert method group WithoutSupport' to non-delegate type bool’. Consider using parentheses to invoke the method

Assets/Scripts/SearchEngine.cs(63,17): error CS0428: Cannot convert method group ResolutionModels' to non-delegate type bool’. Consider using parentheses to invoke the method

Its not there because… It’s not there… It’s not a Unity problem, its a problem with whatever framework you’re using here.

What Framework is this in? Maybe you’ve imported an update and only updated some of the files.

If the script is wrong then the script is wrong, it’s probably because I don’t understand some fundamentals. I’m just trying to understand how to have a variable represent a boolean. CurrentBool is supposed to be either WithSupport, WithoutSupport, or ResolutionModel. I don’t know how to make it equal that without getting an error.

there is no CurrentBool in your ModelProperties class. The Script "SearchEngine " hast the CurrentBool variable

CurrentBool is supposed to be either “WithSupport”, “WithoutSupport” or “ResolutionModel”. It depends what the player clicks on. That’s why I did

void WithSupport ()
{
CurrentBool = WithSupport;
}
…etc etc

What am I doing wrong?

Also you are using

in your SearchEngine class but i don’t see where you have defined them in this class.

You have them in your ModelProperties class but there is no reference to your SearchEngine class

where do you say which values, true or false, “WithSupport”, “WithoutSupport” or “ResolutionModel” have ?

checkboxes in inspector which check for each gameobject you have the script on it ?

Sounds like you could use a crash course in scripting with C# as the problem you now have is extremely basic (and already has been explained in multiple posts). I advise you to go over this series for general c#: C# Fundamentals for Absolute Beginners | Microsoft Learn

And after that dive into Unity specific learning series: Learn

I really don’t like people shoving “basics” stuff on me. I already read and seen so many tutorials. However, people seems to throw about unrelated links that have nothing to do with the questions at hand. I can read C# basics all I want, and I do (currently reading a C# book), but it’s when I actually try to do stuff that I actually learn. Now, I know I can solve it by using “tags” instead of “enums”, but I wanted to see if it was possible to do it by using tags. I could’ve simplified by question by saying, “can I use variables to contain booleans?”. It’s a really simple “No you can’t do”… instead of going through materials that I really 99.9% know to find that 0.1% precent that I don’t that’s even not related to my question, you really could’ve just not have replied. Throwing links about won’t do me no good.

Whether you use tags or enums is 100& unrelated to the problem you have now, as said before, your “ModelProperties” does not have a definition for "CurrentBool ", however, you try to acces it (see @martinmr first post).

void WithSupport () {
   CurrentBool = GetComponent<ModelProperties>().WithSupport;
   x = 0;
   RunList ();
}

void WithoutSupport () {
   CurrentBool = GetComponent<ModelProperties>().WithoutSupport;
   x = 1;
   RunList ();
}

void ResolutionModels () {
   CurrentBool = GetComponent<ModelProperties>().ResolutionModels;
   x = 2;
   RunList ();
}

The script is wrong. Not only does the variable you’re targeting not exist in the class, but even if it did exist you could never do what you’re trying to do because booleans are binary true/false. This doesn’t even have anything to do with C#, the fundamental boolean concept doesn’t allow it. Ever.

Yes, you can’t make a variable that is predefined to be true/false represent the data structure you want.

If you had TWO variable options then you could evaluate the bool’s state like

if (CurrentBool) someString = "Bool was true, this is 'option A'...";
if (!CurrentBool) someString = "Bool was false, this is 'option B'...";

If you want more options you need an Enum or a list to evaluate. This would be like…

public enum Things = {BlueThing, RedThing, OtherThing};
public Things MyOptions;

// ... //

if (MyOptions == Things.BlueThing) someString = "It's the Blue Thing!";

Ahh…an enum array, I think that’s the answer to what I was looking for. Thanks!