Unknown identifier: 'types'. js(38,61)

Im pretty sure ‘types’ is defined but apparently it isnt

#pragma strict

public class weapon extends overWorld
{
	public class weapon
	{
		private var ammo : int;
		private var damage : int;
		private var numberOfBullets : int;
		private var firetype : int;
		private var range :int;
		private var weaponType : types;

		public function weapon()
		{
		ammo = 0;
		damage = 0;
		numberOfBullets = 0;
		firetype = 0;
		range = 0;
		weaponType = types.pistol;
		}

		public function weapon(amm : int, dmg : int, numOfBullets : int, rateOfFire : int, rng : int, typ : types)
		{
		ammo = amm;
		damage = dmg;
		numberOfBullets = numOfBullets;
		firetype = rateOfFire;
		range = rng;
		weaponType = typ;
		}

		public enum types {sword, pistol, shotgun, machinegun, semiauto, sniper};
	}
}

public var sniper : weapon = new weapon(5, 5, 5, 1, 5, types.sniper);

Debug.Log(sniper);

Your code looks extremely strange. In UnityScript every script file is implicitly a class with the name of the file. However you explicitly declare another class in that file which is derived from “overWorld” and called weapon. Weapon derived from overWorld?

Now it gets even stranger. That weapon class is actually empty. You just declared another nested class also called weapon. This class has another nested enum type called “types”.

Beside the fact that type-names should start with a capital letter, this whole setup makes not much sense. If you want to use the “types” enum outside of your two nested classes you have to use:

weapon.weapon.types

I have some counter questions to get behind the reason for your strange setup:

  • What’s the filename of the code you posted?
  • What class is “overWorld”? Is it actually MonoBehaviour or just another custom data-class?