Flashlight Script Help...?

Hey, well, I am a major noob in coding, and this is my attempt at a basic flashlight script… I am still wondering what I am doing wrong… The extra variables are to allow it to work with my main Inventory system. Any help would be appreciated!!! :3

  1. Variable names do not have quotes around them.
  2. Lines need to end with a semi-colon.
  3. Your logic needs to be placed inside a function, probably one called Update().
  4. There is no language feature called toggle
  5. To disable a light you’d use lname.enable = false; (Where the light is called lname).
  6. Variables need to have type specified. So, your HadFlashlight is probably a boolean variable.
  7. The && operator is used to combine boolean values, so && 1 is wrong, it might be treated as && true, however that is unnecessary.

There might be other problems with your code. But this should be enough to get you back on track.

You need to look into a coding book first.

  1. A variable assuming you are using javascript has the following context

    var variableName = “string value here”;
    var booleanName = true;

  2. (HasFlashlight && 1) is the same as (HasFlashlight) because 1 is always true

  3. toggle enable.Light; I’m not even sure the intent of this, but I’m assuming you want to set a light object on and off

    var light; //Some flashlight GameObject

    if (Input.GetKeyDown(KeyCode.E) && (HasFlashlight)) light.enabled = ! light.enabled; //Set the enabled state to the opposite of it’s current value