Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by GKdev1980 · Dec 09, 2013 at 07:53 PM · bce0005unknown identifier

Another "BCE0005: Unknown identifier:" error (following tutorial)

I know it's been discussed again and again, I'm just curious.

I've started the "Digital Tutors - Introduction to Scripting in Unity" tutorial series, still going through some basic stuff, at some point there's a script when he first discusses custom functions:

function Update () { if(Input.GetKeyUp("space")) { WeaponSearch(); } }

function WeaponSearch() { weapon = Random.Range(1, 5);

 switch(weapon)
 {
 case 1:
     weaponName = "sword";
     DisplayMessage(weaponName);
     break;
 case 2:
      weaponName = "axe";
      DisplayMessage(weaponName);
      break;
 case 3:
     weaponName = "dagger";
     DisplayMessage(weaponName);
      break;
 case 4:
      weaponName = "bow";
      DisplayMessage(weaponName);
      break;
 default:
     Debug.Log("You need to find a weapon!");
 }

}

function DisplayMessage(weaponName) { Debug.Log("You found " + weaponName + "!"); }

when I copy it and try to add it to a gameObject, I get an error BCE0005: Unknown identifier: 'weapon'. Now I've done some amateur coding in the past, I'm not completely new to some basic notions, I personally find it logical to get an error, since the variable is not declared earlier. I edited the line to: var weapon = Random.Range(1, 5); and it works just fine.

The thing is, that watching the video tutorial, he uses the unedited script and it works just fine (!!!!!!). That is WITHOUT the "var" in front of the "weapon = Random.Range(1, 5);". He get no errors or anything.

I'm wondering why is that. Does it have anything to do with the Unity version or anything? I go on, and he introduces us to loops with a statement: for (i=1; i<5; i++); without declaring the 'i' variable up ahead. And it works just fine!!

What exactly is going on?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by robertbu · Dec 09, 2013 at 07:57 PM

As an educated guess, I'll bet you are using #pragma strict at the top of the file and the tutorial is not. There are sound performance and quality reasons for using #pragma strict and declaring your variables.

There is some reading here about static vs. dynamic typing and the implication for performance:

http://docs.unity3d.ru/ScriptReference/index.Performance_Optimization.html

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JChilton · Dec 09, 2013 at 08:03 PM 0
Share

What this guy said. An alternative is that he declared 'weapon' elsewhere, and is only setting it in this method.

avatar image robertbu · Dec 09, 2013 at 08:10 PM 1
Share

@JChilton - possible, but the for() loop also works. It would be unlikely for 'i' to be declared outside this function. That's what clued me in that this is likely a dynamic typing situation.

avatar image GKdev1980 · Dec 10, 2013 at 10:21 AM 0
Share

I went through a brief search on

 #pragma strict

, it is noted that you have to explicitly declare the variable type. I've created a test script, I would say that's half true. It allows me to declare and instantiate a variable like this:

var x = 3; var y = 5.5; var z;

without me needing to declare that x is an integer or y is a float.

So I guess I can get away with type declaration as long as I declare the variable name and/or an initial value?

But is this really a good practice? I mean, maybe I could save calculations and resources in unity if I declared the type myself.

avatar image rutter · Jun 06, 2014 at 05:37 PM 0
Share

UnityScript will try to infer a type, in the exact scenario you described: when you declare the variable and give it a value on the same line. It's not always right, but it's usually a good guess.

The type inference happens at compile-time, so it's all set up and ready before the game ever runs.

On the other hand, if strict mode is off, dynamic typing is enabled, and you're back to runtime type checks. Saves the developer some trouble, at the cost of performance penalties.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Only in Mobile BCE0005: Unknown identifier 2 Answers

BCE0005 unknow identifier 'rigidbody' 0 Answers

BCE0005 Unknown identifier issue 1 Answer

Publish 2D tutorial to IOS problem 0 Answers

Error building 2D Gameplay tutorial 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges